#include #include #include #include #include #include using namespace std; const double PI = 3.1415926535; typedef pair xy; typedef int flag; // 0x01 (0,0) 0x02 (0,1) 0x04 (1,0) 0x08 (1,1) const int topleft = 0x01; const int topright = 0x02; const int bottomleft = 0x04; const int bottomright = 0x08; #define m_(x,y) make_pair(x,y) int main(void) { ifstream ifs("circle.txt"); int n; int nc = 0; while(ifs >> n) { if(n == 0) break; set points; map grids; for(int i = 0; i < n; i++){ int x, y; ifs >> x >> y; points.insert(m_(x,y)); grids[m_(x-1, y-1)] |= bottomright; grids[m_(x , y-1)] |= bottomleft; grids[m_(x-1, y )] |= topright; grids[m_(x , y )] |= topleft; } double area = 0.; for(map::iterator it = grids.begin(); it != grids.end(); it++) { switch(it -> second){ case 0x00: area += 0.; break; case 0x01: case 0x02: case 0x04: case 0x08: area += PI / 4.; break; case 0x03: case 0x05: case 0x0a: case 0x0c: area += sqrt(3.) /4. + PI / 6.; break; default: area += 1.; } } if(nc != 0) printf("\n"); printf("Data set #%d: Total area = %.4f square meters.\n", nc+1, area); nc ++; } }