Line 1: | A, B, and N, space separated (1 <= A,B <= 10,000) |
Lines 2-N+1: | Five integers: llx, lly, urx, ury, color: the lower left coordinates and upper right coordinates of the rectangle whose color is `color' (1 <= color <= 2500) to be placed on the white sheet. The color 1 is the same color of white as the sheet upon which the rectangles are placed. |
/* ID: guo geer PROG: rect1 LANG: C++ */ #include<iostream> #include<fstream> using namespace std; struct rectangle { int x1, y1; int x2, y2; }; int c[100000]; rectangle rec[100000]; int line(int a, int b, int x, int y) // a < b, x < y, [a, b]&[x, y] != NULL { if(x > a && x < b) return 1; if(y > a && y < b) return 1; if(x <= a && y >= b) return 1; return 0; } int main() { ifstream fin("rect1.in"); ofstream fout("rect1.out"); int a, b, n; int i,j,k; while(fin>>a>>b>>n) { int count = 0; rec[0].x1 = 0, rec[0].y1 = 0; rec[0].x2 = a, rec[0].y2 = b; c[0] = 1; count ++; int x1, y1, x2, y2, col; for(k=0; k<n; k++) { fin>>x1>>y1>>x2>>y2>>col; for(i=0; i<count; i++) { if(rec[i].x1 >= x1 && rec[i].x2 <= x2 && rec[i].y1 >= y1 && rec[i].y2 <= y2) { c[i] = 0; } else if(rec[i].y1 < y1 && rec[i].y2 > y1 && line(rec[i].x1, rec[i].x2, x1, x2)) { rec[count].x1 = rec[i].x1; rec[count].y1 = y1; rec[count].y2 = rec[i].y2; rec[count].x2 = rec[i].x2; c[count] = c[i]; count ++; rec[i].y2 = y1; } else if(rec[i].x1 < x2 && rec[i].x2 > x2 && line(rec[i].y1, rec[i].y2, y1, y2)) { rec[count].x2 = x2; rec[count].y2 = rec[i].y2; rec[count].y1 = rec[i].y1; rec[count].x1 = rec[i].x1; c[count] = c[i]; count ++; rec[i].x1 = x2; } else if(rec[i].y1 < y2 && rec[i].y2 > y2 && line(rec[i].x1, rec[i].x2, x1, x2)) { rec[count].x1 = rec[i].x1; rec[count].y1 = rec[i].y1; rec[count].y2 = y2; rec[count].x2 = rec[i].x2; c[count] = c[i]; count ++; rec[i].y1 = y2; } else if(rec[i].x1 < x1 && rec[i].x2 > x1 && line(rec[i].y1, rec[i].y2, y1, y2)) { rec[count].x1 = x1; rec[count].y1 = rec[i].y1; rec[count].y2 = rec[i].y2; rec[count].x2 = rec[i].x2; c[count] = c[i]; count ++; rec[i].x2 = x1; } } int count_1 = 0; for(j=0; j<count; j++) if(c[j] != 0) { rec[count_1] = rec[j]; c[count_1] = c[j]; count_1 ++; } count = count_1; rec[count].x1 = x1; rec[count].y1 = y1; rec[count].x2 = x2; rec[count].y2 = y2; c[count] = col; count ++; } int res[2501]; for(i=0; i<= 2500; i++) res[i] = 0; for(i=0; i<count; i++) res[c[i]] += (rec[i].y2 - rec[i].y1) * (rec[i].x2 - rec[i].x1); for(i=1; i<= 2500; i++) if(res[i] != 0) fout<<i<<' '<<res[i]<<endl; } return 0; }