codevs3044 线段树+扫描线
3044 矩形面积求并
http://hzwer.com/879.html
扫描线
1 // #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 #include <sstream> 6 #include <string> 7 #include <algorithm> 8 #include <list> 9 #include <map> 10 #include <vector> 11 #include <queue> 12 #include <stack> 13 #include <cmath> 14 #include <cstdlib> 15 // #include <conio.h> 16 using namespace std; 17 #define clc(a,b) memset(a,b,sizeof(a)) 18 #define inf 0x3f3f3f3f 19 #define lson l,mid,rt<<1 20 #define rson mid+1,r,rt<<1|1 21 const int N = 1100; 22 const int MOD = 1e9+7; 23 #define LL long long 24 #define mi() (l+r)>>1 25 double const pi = acos(-1); 26 27 // inline int r() { 28 // int x=0,f=1;char ch=getchar(); 29 // while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();} 30 // while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f; 31 // } 32 int n; 33 double hashh[N<<2]; 34 double sum[N<<2]; 35 int color[N<<2]; 36 struct Edge{ 37 double x1,x2,y; 38 int flag; 39 bool operator < (const Edge &a) const{ 40 return y<a.y; 41 } 42 }e[N<<2]; 43 44 int b_s(double x){ 45 int l=1,r=2*n; 46 int mid; 47 while(l<=r){ 48 mid=(l+r)>>1; 49 if(hashh[mid]==x) return mid; 50 else if(hashh[mid]<x) l=mid+1; 51 else r=mid-1; 52 } 53 } 54 55 void pushdown(int rt,int l,int r){ 56 if(color[rt]) sum[rt]=hashh[r+1]-hashh[l]; 57 else if(l==r) sum[rt]=0; 58 else sum[rt]=sum[rt<<1]+sum[rt<<1|1]; 59 } 60 61 void update(int l,int r,int rt,int x,int y,int f){ 62 if(x==l&&y==r){ 63 color[rt]+=f; 64 pushdown(rt,l,r); 65 return; 66 } 67 int mid=mi(); 68 if(y<=mid) update(l,mid,rt<<1,x,y,f); 69 else if(x>mid) update(mid+1,r,rt<<1|1,x,y,f); 70 else { 71 update(l,mid,rt<<1,x,mid,f); 72 update(mid+1,r,rt<<1|1,mid+1,y,f); 73 } 74 pushdown(rt,l,r); 75 } 76 int main(){ 77 // int n; 78 while(scanf("%d",&n)){ 79 if(n==0) 80 break; 81 clc(color,0); 82 clc(sum,0); 83 double x1,x2,y1,y2; 84 for(int i=1;i<=n;i++){ 85 scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); 86 e[i*2-1].x1=e[i*2].x1=x1; 87 e[i*2-1].x2=e[i*2].x2=x2; 88 e[i*2-1].y=y1;e[i*2].y=y2; 89 e[i*2-1].flag=1;e[i*2].flag=-1; 90 hashh[i*2-1]=x1;hashh[i*2]=x2; 91 } 92 sort(e+1,e+1+2*n); 93 sort(hashh+1,hashh+1+2*n); 94 double ans=0; 95 for(int i=1;i<=2*n;i++){ 96 int l=b_s(e[i].x1),r=b_s(e[i].x2)-1; 97 // cout<<"l:"<<l<<" "<<"r:"<<r<<endl; 98 if(l<=r) update(1,2*n,1,l,r,e[i].flag); 99 // cout<<"sum[1]"<<sum[1]<<endl; 100 ans+=sum[1]*(e[i+1].y-e[i].y); 101 } 102 printf("%.2f\n",ans); 103 } 104 return 0; 105 }
转载于:https://www.cnblogs.com/ITUPC/p/5643275.html
codevs3044 线段树+扫描线相关推荐
- 线段树扫描线求矩形周长详解
线段树扫描线求矩形周长详解 原创 wucstdio 最后发布于2018-04-24 16:12:09 阅读数 841 收藏 发布于2018-04-24 16:12:09 版权声明:本文为博主原创文章, ...
- hdu3255 线段树扫描线求体积
题意: 给你n个矩形,每个矩形上都有一个权值(该矩形单位面积的价值),矩形之间可能重叠,重叠部分的权值按照最大的算,最后问这n个矩形组成的图形的最大价值. 思路: 线段树扫描线 ...
- hdu1542 线段树扫描线求矩形面积的并
题意: 给你n个正方形,求出他们的所占面积有多大,重叠的部分只能算一次. 思路: 自己的第一道线段树扫描线题目,至于扫描线,最近会写一个总结,现在就不直接在这里写了,说下我的方 ...
- hdu 1542 Atlantis (线段树+扫描线)
http://acm.hdu.edu.cn/showproblem.php?pid=1542 单纯的线段树+扫描线求面积并,需要离散化. code: #include <cstdlib> ...
- HDU 1264 Counting Squares (线段树-扫描线-矩形面积并)
版权声明:欢迎关注我的博客.本文为博主[炒饭君]原创文章,未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/25471349 P ...
- bzoj 1645: [Usaco2007 Open]City Horizon 城市地平线(线段树扫描线)
1645: [Usaco2007 Open]City Horizon 城市地平线 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 732 Solved: ...
- 亚特兰蒂斯【线段树+扫描线+离散化】
亚特兰蒂斯[线段树+扫描线+离散化] POJ1151.ACwing247 题目: 有几个古希腊书籍中包含了对传说中的亚特兰蒂斯岛的描述. 其中一些甚至包括岛屿部分地图. 但不幸的是,这些地图描述了亚特 ...
- 2016 UESTC Training for Data Structures F - 郭大侠与“有何贵干?” CDOJ 1335 线段树 扫描线 离散化
F - 郭大侠与"有何贵干?" 就是给一个三维空间,和N个长方体,问覆盖K次的体积 x和y都是1e9,但是z是[1,3],所以可以把这个分为两个二维平面,求被覆盖K次的面积,最后加 ...
- 单调栈 or 线段树扫描线 ---- E. Delete a Segment [单调栈+二分] [扫描线处理空白位置的技巧乘2]
题目链接 题目大意: 给出nnn个线段代表集合,现在问若可以将其中任意一个线段删除,则能够形成最多多少个独立的集合(取并集后) 解题思路1: 首先我们先对线段按照起点排序 那么我们枚举删除的线段iii ...
- Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树扫描线
D. Vika and Segments 题目连接: http://www.codeforces.com/contest/610/problem/D Description Vika has an i ...
最新文章
- 怎么样才能快速的把淘宝店铺推广出去
- MySQL中的分页查询
- ABAP代码自动完成实现原理
- 查看ios设备型号网址
- 首次公开!单日600PB的计算力--阿里巴巴EB级大数据平台的进击
- [收藏]网络营销十道羊皮卷
- 图像处理与图像识别笔记(六)图像增强3
- h5禁用浏览器下载视频_Flash正式被全球禁用,只有中国版还活着
- OJ1090: 整数幂(多实例测试)(C语言)
- 西瓜书《贝叶斯》朴素贝叶斯公式推导
- java的trans文件大小写_文件大小写转换与后缀不变
- 修改redis配置文件,并以指定配置文件的方式启动
- 高等数学张宇18讲 第四讲 一元函数微分学的几何应用
- mysql端口establish_PHP/MySQL Dev. Primer (1) Establish Env.
- 力扣刷题 DAY_80 贪心
- CVPR 2020 论文大盘点-人脸技术篇
- Python是个啥?为啥大家都在学?
- web微信js WechatWeb js方法
- iPhone12概念图来袭,最为期待的样子来了
- android app trifit_Android人脸识别app——基于Face++,MVP+Retofit+RxJava+Dagger高度解耦
热门文章
- 十进制转换成二进制java_计算机为什么采用二进制?
- Hyperledger fabric v2.3 交易流程 翻译
- 区块链Hyperledger Fabric背书过程中链码是并行还是串行?
- 复习-java运行的整个流程
- java executor spring_java - Spring TaskExecutor实现 - 堆栈内存溢出
- 基于SSM的电影购票系统
- 五、Linux常用命令——帮助命令
- 2.1.PHP7.1 狐教程-【PHP基础】
- JAVA Maven和ANT 安装 Linux(Ubuntu/Centos),Mac
- SpringMVC 注解 @Scope、@PostConstruct、@PreDestroy、@ComponentScan