Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11997 Accepted Submission(s): 5056
node
1 #include <iostream> 2 #include <algorithm> 3 #include <cmath> 4 #include <cstring> 5 #include <map> 6 #include <vector> 7 #include <queue> 8 #include <list> 9 #include <cstdio> 10 #define rep(i,a,b) for(int (i) = (a);(i) <= (b);++ (i)) 11 #define per(i,a,b) for(int (i) = (a);(i) >= (b);-- (i)) 12 #define mem(a,b) memset((a),(b),sizeof((a))) 13 #define FIN freopen("in.txt","r",stdin) 14 #define FOUT freopen("out.txt","w",stdout) 15 #define IO ios_base::sync_with_stdio(0),cin.tie(0) 16 #define mid ((l+r)>>1) 17 #define ls (id<<1) 18 #define rs ((id<<1)|1) 19 #define INF 0x3f3f3f3f 20 typedef long long ll; 21 const ll mod = 1e8+7; 22 const ll eps = 1e-12; 23 using namespace std; 24 const int N = 210; 25 26 int n; 27 double xp1, yp1, xp2, yp2, y[N*4]; 28 struct Line{ 29 double x, y1, y2; 30 int f; 31 bool operator < (const Line &r) const { 32 return x < r.x; 33 } 34 }hashy[N*4]; 35 struct Node{ 36 double sum; 37 int lazy; 38 }node[N*4]; 39 40 void pushUp(int id, int l, int r){ 41 if(node[id].lazy > 0) node[id].sum = y[r-1]-y[l-2]; 42 else if(l == r) node[id].sum = 0; 43 else 44 node[id].sum = node[ls].sum+node[rs].sum; 45 } 46 void build(int id, int l, int r){ 47 node[id].lazy = 0; 48 if(l == r){ 49 node[id].sum = 0; 50 return ; 51 } 52 build(ls, l, mid); 53 build(rs, mid+1, r); 54 } 55 void update(int id, int l, int r, int ql, int qr, int p){ 56 if(ql == l && qr == r){ 57 node[id].lazy += p; 58 pushUp(id, l, r); 59 return ; 60 } 61 if(qr <= mid) update(ls, l, mid, ql, qr, p); 62 else if(ql > mid) 63 update(rs, mid+1, r, ql, qr, p); 64 else{ 65 update(ls, l, mid, ql, mid, p); 66 update(rs, mid+1, r, mid+1, qr, p); 67 } 68 pushUp(id, l, r); 69 } 70 int main() 71 { 72 //FIN; 73 int w_w = 0; 74 while(cin >> n, n != 0){ 75 int len = 0; 76 rep(i, 1, n){ 77 cin >> xp1 >> yp1 >> xp2 >> yp2; 78 hashy[len].x = xp1; hashy[len].y1 = yp1; 79 hashy[len].y2 = yp2; hashy[len].f = 1; y[len++] = yp1; 80 hashy[len].x = xp2; hashy[len].y1 = yp1; 81 hashy[len].y2 = yp2; hashy[len].f = -1; y[len++] = yp2; 82 } 83 sort(hashy, hashy+len); 84 sort(y, y+len); 85 86 build(1, 1, n*2); 87 double ans = 0; 88 rep(i, 0, len-1){ 89 int pos1 = lower_bound(y, y+len, hashy[i].y1)-y+1; 90 int pos2 = lower_bound(y, y+len, hashy[i].y2)-y+1; 91 if(i) ans += node[1].sum*(hashy[i].x-hashy[i-1].x); 92 update(1, 1, n*2, pos1+1, pos2, hashy[i].f); 93 //cout << "sum: " << node[1].sum << endl; 94 } 95 cout << "Test case #" << ++w_w << endl; 96 printf("Total explored area: %.2lf\n\n", ans); 97 } 98 return 0; 99 }