标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 20223 | Accepted: 7634 |
Description
Input
Output
Sample Input
2 10 10 20 20 15 15 25 25.5 0
Sample Output
Test case #1 Total explored area: 180.00
Source
#include <iostream> #include <cmath> #include <vector> #include <cstdlib> #include <cstdio> #include <cstring> #include <queue> #include <stack> #include <list> #include <algorithm> #include <map> #include <set> #define LL long long #define Pr pair<int,int> #define fread() freopen("in.in","r",stdin) #define fwrite() freopen("out.out","w",stdout) using namespace std; const int INF = 0x3f3f3f3f; const int msz = 10000; const int mod = 1e9+7; const double eps = 1e-8; struct Line { double y1,y2; double x; int ad; bool operator < (const struct Line a)const { return x < a.x; } }; Line ln[233]; double yp[233]; int yv[233]; int tpy; int main() { //fread(); //fwrite(); int n,z = 1; double x1,y1,x2,y2; while(~scanf("%d",&n) && n) { int tmp = 0; tpy = 0; for(int i = 0; i < n; ++i) { scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); ln[tmp].x = x1; ln[tmp+1].x = x2; ln[tmp].y1 = ln[tmp+1].y1 = y1; ln[tmp].y2 = ln[tmp+1].y2 = y2; ln[tmp].ad = 1; ln[tmp+1].ad = -1; tmp += 2; yp[tpy++] = y1; yp[tpy++] = y2; } sort(yp,yp+tpy); tpy = 0; for(int i = 0; i < tmp; ++i) { if(!i || yp[i] > yp[tpy-1]) yp[tpy++] = yp[i]; } double ans = 0; memset(yv,0,sizeof(yv)); sort(ln,ln+tmp); for(int i = 0; i < tmp; ++i) { int l,r; l = r = -1; for(int j = 0; j < tpy && (l == -1 || r == -1); ++j) { if(ln[i].y1 == yp[j]) l = j; if(ln[i].y2 == yp[j]) r = j; } while(l < r) yv[l++] += ln[i].ad; if(i == tmp-1 || ln[i].x == ln[i+1].x) continue; int j = 0; while(j < tpy) { while(j < tpy && yv[j] == 0) ++j; l = j; while(j < tpy && yv[j]) ++j; r = j; //printf("%f %f\n",yp[r],yp[l]); if(r > l) ans += (yp[r]-yp[l])*(ln[i+1].x-ln[i].x); } // printf("%f\n",ans); } printf("Test case #%d\n",z++); printf("Total explored area: %.2f\n\n",ans); } return 0; }
标签:
原文地址:http://blog.csdn.net/challengerrumble/article/details/51030037