标签:def 计算 std ted 左右 sea tor memset i++
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7779 Accepted Submission(s): 3923
1 //2018-09-09 2 #include <cstdio> 3 #include <cstring> 4 #include <iostream> 5 #include <algorithm> 6 #define lson (id<<1) 7 #define rson ((id<<1)|1) 8 using namespace std; 9 10 const int N = 2000; 11 const double EPS = 0.0001; 12 13 struct Node{ 14 double sum; 15 }tree[N<<2]; 16 int cnt[N], len; 17 double x[N]; 18 19 void build(){ 20 memset(tree, 0, sizeof(tree)); 21 } 22 23 void update(int id, int L, int R, int pos, int val){ 24 if(L==R){ 25 cnt[pos] += val; 26 if(cnt[pos]>1)tree[id].sum = x[pos+1]-x[pos]; 27 else tree[id].sum = 0; 28 return; 29 } 30 int mid = (L+R)/2; 31 if(pos <= mid)update(lson, L, mid, pos, val); 32 else update(rson, mid+1, R, pos, val); 33 tree[id].sum = tree[lson].sum+tree[rson].sum; 34 } 35 36 struct Line{ 37 double x0, x1, y; 38 int fg; 39 bool operator<(const Line l) const{ 40 return y < l.y; 41 } 42 }line[N<<2]; 43 44 int bsearch(int l, int r, int key){ 45 while(l < r){ 46 int mid = (l+r)>>1; 47 if(key <= x[mid])r = mid; 48 else l = mid+1; 49 } 50 return l; 51 } 52 53 int main() 54 { 55 int T, n, kase = 0; 56 scanf("%d",&T); 57 while(T--){ 58 scanf("%d", &n); 59 double x0, y0, x1, y1; 60 len = 0; 61 for(int i = 1; i <= n; i++){ 62 scanf("%lf%lf%lf%lf", &x0, &y0, &x1, &y1); 63 int a = i*2-1, b = i*2; 64 line[a].x0 = x0, line[a].x1 = x1, line[a].y = y0, line[a].fg = 1; 65 line[b].x0 = x0, line[b].x1 = x1, line[b].y = y1, line[b].fg = -1; 66 x[++len] = x0, x[++len] = x1; 67 } 68 n*=2; 69 sort(x+1, x+1+n); 70 sort(line+1, line+1+n); 71 memset(cnt, 0, sizeof(cnt)); 72 build(); 73 double ans = 0; 74 for(int i = 1; i <= n; i++){ 75 ans += tree[1].sum*(line[i].y-line[i-1].y); 76 int l = lower_bound(x+1, x+1+n, line[i].x0)-x; 77 int r = lower_bound(x+1, x+1+n, line[i].x1)-x; 78 for(int j = l; j < r; j++){ 79 update(1, 1, n-1, j, line[i].fg); 80 } 81 } 82 printf("%.2lf\n", ans+EPS); 83 } 84 85 return 0; 86 }
标签:def 计算 std ted 左右 sea tor memset i++
原文地址:https://www.cnblogs.com/Penn000/p/9612770.html