View Code of Problem 15

#include<stdio.h>
#include <math.h>
#define DIS(a,b) sqrt( (pos[a].x - pos[b].x) * (pos[a].x - pos[b].x) + (pos[a].y - pos[b].y) * (pos[a].y - pos[b].y) )
#define DISS (min * min)
struct poss
{
    double x;
    double y;
};
int main()
{
	int n, m, i, j, k = 0;
	double s, ss, min, temp, x2, x3;
	struct poss pos[10];

	x2 = sqrt(2);
	x3 = sqrt(3);
	scanf("%d", &n);
	while (n != (-1))
	//while (scanf("%d", &n) != EOF)
	{
	    ss = 0;
	    k++;

	    for (i=0; i<n; i++)
        {
            scanf("%d", &m);
            for (j=0; j<m; j++)
                scanf("%lf %lf", &pos[j].x, &pos[j].y);

            min = DIS(0,1);
            for (j=2; j<m; j++)
            if (temp=DIS(0,j)< min)
                min = temp;
                //dis
            if (m == 3)
                ss += DISS * x3 / 4;
            if (m == 4)
                ss += DISS;
            if (m == 5)
                ss += 1.72048 * DISS;
            if (m == 6)
                ss += DISS * x3 / 4 * 6;
            if (m == 7)
                ss += 3.63391 * DISS;
            if (m == 8)
                ss += DISS * (2 + 2 * x2);
        }

        s = ss;
        printf("Case #%d: %.4f\n", k, s);
        scanf("%d", &n);
	}
	return (0);
}

Double click to view unformatted code.


Back to problem 15