USACO 5.3 Window Area(模拟)
坐标不全是左上角,右下角的。2Y,怎么可以写的这么麻烦。。。暴力水过。
1 /* 2 ID: cuizhe 3 LANG: C++ 4 TASK: window 5 */ 6 #include <iostream> 7 #include <cstdio> 8 #include <cstring> 9 #include <cmath> 10 #include <algorithm> 11 #include <vector> 12 #include <string> 13 #include <queue> 14 #include <set> 15 using namespace std; 16 #define INF 10000000 17 struct node 18 { 19 int x1,y1,x2,y2; 20 }p[201]; 21 int o[201]; 22 void add(int num,int x1,int y1,int x2,int y2) 23 { 24 p[num].x1 = min(x1,x2); 25 p[num].y1 = max(y1,y2); 26 p[num].x2 = max(x1,x2); 27 p[num].y2 = min(y1,y2); 28 } 29 int judge(int num,int x1,int y1,int x2,int y2) 30 { 31 if(p[num].x1 <= x1&&p[num].y1 >= y1&&x2 <= p[num].x2&&y2 >= p[num].y2) 32 return 1; 33 else 34 return 0; 35 } 36 int main() 37 { 38 char ch,na; 39 int i,x1,x2,y1,y2,t,num,bot; 40 num = 1;bot = 0; 41 freopen("window.in","r",stdin); 42 freopen("window.out","w",stdout); 43 for(i = 0;i <= 200;i ++) 44 o[i] = -INF; 45 while(scanf("%c",&ch)!=EOF) 46 { 47 if(ch == 'w') 48 { 49 scanf("(%c,%d,%d,%d,%d)%*c",&na,&x1,&y1,&x2,&y2); 50 t = na; 51 add(t,x1,y1,x2,y2); 52 o[t] = num ++; 53 } 54 else if(ch == 'd') 55 { 56 scanf("(%c)%*c",&na); 57 o[na] = -INF; 58 } 59 else if(ch == 't') 60 { 61 scanf("(%c)%*c",&na); 62 o[na] = num ++; 63 } 64 else if(ch == 'b') 65 { 66 scanf("(%c)%*c",&na); 67 o[na] = bot--; 68 } 69 else if(ch == 's') 70 { 71 scanf("(%c)%*c",&na); 72 set<int> r; 73 set<int> c; 74 set<int>::iterator it1; 75 set<int>::iterator it2; 76 set<int>::iterator te; 77 for(i = 0;i <= 130;i ++) 78 { 79 if(o[i] >= o[na]) 80 { 81 r.insert(p[i].x1); 82 r.insert(p[i].x2); 83 c.insert(p[i].y1); 84 c.insert(p[i].y2); 85 } 86 } 87 int temp1,temp2,sum; 88 sum = 0; 89 for(it1 = r.begin();it1 != r.end();it1 ++) 90 { 91 te = ++ it1; 92 temp1 = *te; 93 it1 --; 94 if(te == r.end()) break; 95 96 for(it2 = c.begin();it2 != c.end();it2 ++) 97 { 98 te = ++it2; 99 temp2 = *te; 100 it2 --; 101 if(te == c.end()) break; 102 if(judge(na,*it1,temp2,temp1,*it2)) 103 { 104 for(i = 0;i <= 128;i ++) 105 { 106 if(o[i] > o[na]) 107 { 108 if(judge(i,*it1,temp2,temp1,*it2)) 109 break; 110 } 111 } 112 if(i != 129) 113 { 114 sum += (temp1 - *it1)*(temp2 - *it2); 115 } 116 } 117 } 118 } 119 sum = (p[na].x2-p[na].x1)*(p[na].y1-p[na].y2) - sum; 120 printf("%.3lf\n",sum*100.0/(p[na].x2-p[na].x1)/(p[na].y1-p[na].y2)); 121 } 122 } 123 return 0; 124 }