double J(double *a) { double res = 0.0; for (int i = 0; i < POINTS_INNER; i++) { res += sqr(laplace(a, test_points[i][0], test_points[i][1]) \ - f(test_points[i][0], test_points[i][1], 0.0, 0.0, 0.0)); } for (int i = POINTS_INNER; i < POINTS_INNER + POINTS_BORDER; ++i) { res += DELTA * sqr(calc(a, test_points[i][0], test_points[i][1]) \ - left_border(test_points[i][1])); } for (int i = POINTS_INNER + POINTS_BORDER; i < POINTS_INNER + 2 * POINTS_BORDER; ++i) { res += DELTA * sqr(calc(a, test_points[i][0], test_points[i][1]) \ - bottom_border(test_points[i][0])); } for (int i = POINTS_INNER + 2 * POINTS_BORDER; i < POINTS_INNER + 3 * POINTS_BORDER; ++i) { res += DELTA * sqr(calc(a, test_points[i][0], test_points[i][1]) \ - top_border(test_points[i][0])); } return res; }
int main() { Point p1, p2, p3; int i, j, ntrees; while(scanf("%lf%lf%lf%lf%lf%lf", &p1.x, &p1.y, &p2.x, &p2.y, &p3.x, &p3.y)) { if(p1.x == 0 && p1.y == 0 && p2.x == 0 && p2.y == 0 && p3.x == 0 && p3.y == 0) break; ntrees = 0; reorder_vertices(p1, p2, p3); int left = left_border(p1, p2, p3); if(left < 1) left = 1; int right = right_border(p1, p2, p3); if(right > 99) right = 99; int bottom = bottom_border(p1, p2, p3); if(bottom < 1) bottom = 1; int top = top_border(p1, p2, p3); if(top > 99) top = 99; for(i = left; i <= right; i++) { for(j = bottom; j <= top; j++) { Point tree = { (double)i, (double)j }; if(on_edge(p1, p2, tree) || on_edge(p2, p3, tree) || on_edge(p3, p1, tree) || ccw(p1, p2, tree) && ccw(p2, p3, tree) && ccw(p3, p1, tree)) { ntrees++; } } } printf("%4d\n", ntrees); } return 0; }