覆盖的面积

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4040    Accepted Submission(s): 1995

Problem Description
给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积.

 
Input

入数据的第一行是一个正整数T(1<=T<=100),代表测试数据的数量.每个测试数据的第一行是一个正整数N(1<=N&
lt;=1000),代表矩形的数量,然后是N行数据,每一行包含四个浮点数,代表平面上的一个矩形的左上角坐标和右下角坐标,矩形的上下边和X轴平行,
左右边和Y轴平行.坐标的范围从0到100000.

注意:本题的输入数据较多,推荐使用scanf读入数据.

 
Output
对于每组测试数据,请计算出被这些矩形覆盖过至少两次的区域的面积.结果保留两位小数.
 
Sample Input
2
 
5
1 1 4 2
1 3 3 7
2 1.5 5 4.5
3.5 1.25 7.5 4
6 3 10 7
 
3
0 0 1 1
1 0 2 1
2 0 3 1
 
Sample Output
7.63
0.00
 
 
交G++迷之WA。。无语
C++可过。
 
  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <cstring>
  4. #include <vector>
  5. #include <map>
  6. using namespace std;
  7. #define root 1,(n<<1)+10,1
  8. #define lson l,mid,rt<<1
  9. #define rson mid+1,r,rt<<1|1
  10. #define lr rt<<1
  11. #define rr rt<<1|1
  12.  
  13. const int N = ;
  14.  
  15. struct Point {
  16. double x , y1 , y2 ;
  17. int v ;
  18. bool operator < ( const Point &a ) const {
  19. return x < a.x ;
  20. }
  21. }p[N];
  22. int n , tot , tt ;
  23. vector<double>e;
  24. double c[N<<] ;
  25.  
  26. void addpoint( double x , double y1 , double y2 , int v ) {
  27. p[tot].x = x , p[tot].y1 = y1 , p[tot].y2 = y2 , p[tot].v = v , tot++ ;
  28. }
  29. map<double,int>mp;
  30.  
  31. void lisan() {
  32. mp.clear();
  33. sort( e.begin() , e.end() ) ;
  34. tt = ;
  35. for( int i = ; i < e.size() ; ++i ) {
  36. if( e[i] != e[i-] ) e[tt++] = e[i] ;
  37. }
  38. for( int i = ; i < tt ; ++i ) {
  39. c[i+] = e[i] ;
  40. mp[e[i]] = i+ ;
  41. }
  42. }
  43.  
  44. int cnt[N<<] , lazy[N<<] ;
  45.  
  46. double date[N<<] ;
  47.  
  48. void build( int l , int r , int rt ) {
  49. cnt[rt] = lazy[rt] = ;
  50. if( l == r ) {
  51. date[rt] = c[l+] - c[l];
  52. return ;
  53. }
  54. int mid = (l+r)>>;
  55. build(lson) , build(rson) ;
  56. date[rt] = date[lr] + date[rr];
  57. }
  58.  
  59. void Down( int rt ) {
  60. if( lazy[rt] ) {
  61. cnt[lr] += lazy[rt] ;
  62. cnt[rr] += lazy[rt] ;
  63. lazy[lr] += lazy[rt] ;
  64. lazy[rr] += lazy[rt] ;
  65. lazy[rt] = ;
  66. }
  67. }
  68.  
  69. void Up( int rt ) {
  70. cnt[rt] = min( cnt[lr] , cnt[rr] );
  71. }
  72.  
  73. void update( int l , int r , int rt , int L , int R , int v ) {
  74. if( l == L && r == R ) {
  75. cnt[rt] += v ; lazy[rt] += v ;
  76. return ;
  77. }
  78. int mid = (l+r)>> ;
  79. Down(rt) ;
  80. if( R <= mid ) update(lson,L,R,v) ;
  81. else if( L > mid ) update( rson,L,R,v);
  82. else update(lson,L,mid,v),update(rson,mid+,R,v);
  83. Up(rt);
  84. }
  85.  
  86. double query( int l , int r , int rt , int L , int R ) {
  87. if( cnt[rt] > ) return date[rt] ;
  88. if( l == r ) return ;
  89. Down(rt);
  90. int mid = (l+r)>>;
  91. if( R <= mid ) return query(lson,L,R);
  92. else if( L > mid ) return query(rson,L,R);
  93. else return query(lson,L,mid) + query(rson,mid+,R);
  94. }
  95.  
  96. int main() {
  97. #ifdef LOCAL
  98. freopen("in.txt","r",stdin);
  99. #endif // LOCAL
  100. int _ ; scanf("%d",&_);
  101. while( _-- ) {
  102. scanf("%d",&n);
  103. e.clear();
  104. tot = ;
  105. for( int i = ; i < n ; ++i ) {
  106. double x1 , y1 , x2 , y2 ;
  107. scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
  108. if( y1 > y2 ) swap( y1 , y2 ) ;
  109. addpoint( x1 , y1 , y2 , );
  110. addpoint( x2 , y1 , y2 , - );
  111. e.push_back(y1);
  112. e.push_back(y2);
  113. }
  114. lisan();
  115. sort( p , p + tot ) ;
  116. build(,tt-,);
  117. double ans = ;
  118. update(,tt-,,mp[p[].y1],mp[p[].y2]-,p[].v);
  119. for( int i = ; i < tot ; ++i ) {
  120. ans += ( p[i].x - p[i-].x ) * query(,tt-,,,tt-) ;
  121. update(,tt-,,mp[p[i].y1],mp[p[i].y2]-,p[i].v);
  122. }
  123. printf("%.2lf\n",ans);
  124. }
  125. return ;
  126. }

HDU 1255 覆盖的面积 ( 扫描线 + 离散 求矩阵大于k次面积并 )的更多相关文章

  1. FZU 2187 回家种地 ( 扫描线 + 离散 求矩阵单次覆盖面积 )

    2187 回家种地 Accept: 56    Submit: 230Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem Descript ...

  2. HDU 4417 Super Mario(划分树问题求不大于k的数有多少)

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. HDU - 1255 覆盖的面积(线段树求矩形面积交 扫描线+离散化)

    链接:线段树求矩形面积并 扫描线+离散化 1.给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. 2.看完线段树求矩形面积并 的方法后,再看这题,求的是矩形面积交,类同. 求面积时,用被覆 ...

  4. hdu 1255 覆盖的面积(求覆盖至少两次以上的面积)

    了校赛,还有什么途径可以申请加入ACM校队?  覆盖的面积 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  5. hdu 1255 覆盖的面积(线段树 面积 交) (待整理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 Description 给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积.   In ...

  6. HDU 1255 覆盖的面积 (线段树扫描线+面积交)

    自己YY了一个的写法,不过时间复杂度太高了,网上的想法太6了  题意:给你一些矩阵,求出矩阵的面积并 首先按照x轴离散化线段到线段树上(因为是找连续区间,所以段建树更加好做). 然后我们可以想一下怎样 ...

  7. HDU 1255 覆盖的面积(线段树+扫描线)

    题目地址:HDU 1255 这题跟面积并的方法非常像,仅仅只是须要再加一个变量. 刚開始我以为直接用那个变量即可,仅仅只是推断是否大于0改成推断是否大于1.可是后来发现了个问题,由于这个没有下放,没延 ...

  8. HDU 1255 覆盖的面积 (线段树+扫描线+离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 题意很清楚,就是让你求矩阵之间叠加层数大于1的矩形块的面积和. 因为n只有1000,所以我离散化 ...

  9. hdu 1255 覆盖的面积 (线段树处理面积覆盖问题(模板))

    http://acm.hdu.edu.cn/showproblem.php?pid=1255 覆盖的面积 Time Limit: 10000/5000 MS (Java/Others)    Memo ...

随机推荐

  1. vue+element ui 滚动加载

    <div id="app"> <div class="infinite-list-wrapper" style="overflow: ...

  2. Nginx安装与配置-Centos7

    Nginx是一款高性能免费开源网页服务器,也可用于反向代理和负载均衡服务器.该软件由伊戈尔·赛索耶夫于2004年发布,2019年3月11日,Nginx被F5 Networks以6.7亿美元收购.201 ...

  3. 10java进阶——IO2

    1. Properties类 Properties 类表示了一个持久的属性集.Properties 可保存在流中或从流中加载.属性列表中每个键及其对应值都是一个字符串. 特点: Hashtable的子 ...

  4. stream benchmark 介绍

    英文原版 https://www.cs.virginia.edu/stream/ref.html FAQ中有关于STREAM_ARRAY_SIZE NTIME OFFSET STREAM_TYPE的设 ...

  5. bzoj4773 负环 倍增+矩阵

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4773 题解 最小的负环的长度,等价于最小的 \(len\) 使得存在一条从点 \(i\) 到自 ...

  6. 17 安全字符串 System.Security.SecureString

  7. JS自定义随机数字键盘

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. 洛谷 P4300 BZOJ 1266 [AHOI2006]上学路线route

    题目描述 可可和卡卡家住合肥市的东郊,每天上学他们都要转车多次才能到达市区西端的学校.直到有一天他们两人参加了学校的信息学奥林匹克竞赛小组才发现每天上学的乘车路线不一定是最优的. 可可:“很可能我们在 ...

  9. Python_004(列表和元组)

    一.列表 1. 列表: 列表的创建:li = [],列表中可以放置字符串,元组,列表,字典,列表等各种数据类型,32位的Python可以存放2^32个数据 2. 列表的索引和切片 列表的索引:格式ls ...

  10. 前端JS编码规范

    对初学者来说应该学习的JavaScript编码规范: 传送门: http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=29292475 ...