HDU 1828 Picture 线段树 扫描线
写完后才发现数据是int不是double...
//#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> #include<sstream> #include<cmath> #include<climits> #include<string> #include<map> #include<queue> #include<vector> #include<stack> #include<set> using namespace std; typedef long long ll; typedef pair<int,int> pii; #define pb(a) push_back(a) #define INF 0x1f1f1f1f #define lson idx<<1,l,mid #define rson idx<<1|1,mid+1,r #define PI 3.1415926535898 template<class T> T min(const T& a,const T& b,const T& c) {return min(min(a,b),min(a,c)); } template<class T> T max(const T& a,const T& b,const T& c) {return max(max(a,b),max(a,c)); } void debug() { #ifdef ONLINE_JUDGE #elsefreopen("d:\\in.txt","r",stdin);// freopen("d:\\out1.txt","w",stdout); #endif } int getch() {int ch;while((ch=getchar())!=EOF) {if(ch!=' '&&ch!='\n')return ch;}return EOF; } const int maxn=5000; struct Seg {double a,b,x;int c;Seg(){}Seg(double a,double b,double c,int d):a(a),b(b),x(c),c(d){}bool operator < (const Seg& another) const{return x<another.x;} }; Seg seg[maxn<<1]; double Y[maxn<<1]; int num[maxn<<3]; int flag[maxn<<3]; int point[maxn<<3][2]; double sum[maxn<<3]; int build(int idx,int l, int r) {memset(num,0,sizeof(num));memset(flag,0,sizeof(flag));memset(point,0,sizeof(point));memset(sum,0,sizeof(sum));return 0; } int PushUp(int idx,int l,int r) {if(flag[idx]){num[idx]=2;point[idx][0]=point[idx][1]=1;sum[idx]=Y[r+1]-Y[l];}else if(l!=r){num[idx]=num[idx<<1]+num[idx<<1|1];if(point[idx<<1][1]&&point[idx<<1|1][0])num[idx]-=2;point[idx][0]=point[idx<<1][0];point[idx][1]=point[idx<<1|1][1];sum[idx]=sum[idx<<1]+sum[idx<<1|1];}else{num[idx]=0;point[idx][0]=point[idx][1]=0;sum[idx]=0;}return 0; } int update(int idx,int l,int r,int tl,int tr,int v) {if(tl<=l&&tr>=r){flag[idx]+=v;PushUp(idx,l,r);return 0;}int mid=(r+l)>>1;if(tl<=mid)update(lson,tl,tr,v);if(tr>mid)update(rson,tl,tr,v);PushUp(idx,l,r);return 0; } int main() {int n;while(scanf("%d",&n)!=EOF){int m=0;for(int i=0;i<n;i++){double a,b,c,d;scanf("%lf%lf%lf%lf",&a,&b,&c,&d);seg[m]=Seg(b,d,a,1);Y[m++]=b;seg[m]=Seg(b,d,c,-1);Y[m++]=d;}sort(seg,seg+m);sort(Y,Y+m);int k=1;for(int i=1;i<m;i++)if(Y[i]!=Y[i-1])Y[k++]=Y[i];double res=0;build(1,0,k);for(int i=0;i<m;i++){if(i!=0)res+=(seg[i].x-seg[i-1].x)*num[1];int l=lower_bound(Y,Y+k,seg[i].a)-Y;int r=lower_bound(Y,Y+k,seg[i].b)-Y;double last=sum[1];update(1,0,k,l,r-1,seg[i].c);res+=fabs(sum[1]-last);}printf("%d\n",int(res+0.00001));}return 0; }
View Code
转载于:https://www.cnblogs.com/BMan/p/3316530.html
HDU 1828 Picture 线段树 扫描线相关推荐
- hdu 1542 Atlantis (线段树+扫描线)
http://acm.hdu.edu.cn/showproblem.php?pid=1542 单纯的线段树+扫描线求面积并,需要离散化. code: #include <cstdlib> ...
- HDU - 1542 Atlantis(线段树+扫描线)
题目链接:点击查看 题目大意:给出n个矩形的左下角坐标和右上角坐标,求出其总面积,注意,矩形会重叠,重叠部分只计算一次 题目分析:如果暴力做需要考虑容斥原理,两两矩形组合判断是否重合,十分麻烦而且时间 ...
- Picture 线段树扫描线求轮廓线
http://acm.hdu.edu.cn/showproblem.php?pid=1828 思路来自http://www.cnblogs.com/ka200812/archive/2011/11/1 ...
- HDU 1264 Counting Squares (线段树-扫描线-矩形面积并)
版权声明:欢迎关注我的博客.本文为博主[炒饭君]原创文章,未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/25471349 P ...
- 线段树扫描线求矩形周长详解
线段树扫描线求矩形周长详解 原创 wucstdio 最后发布于2018-04-24 16:12:09 阅读数 841 收藏 发布于2018-04-24 16:12:09 版权声明:本文为博主原创文章, ...
- hdu3255 线段树扫描线求体积
题意: 给你n个矩形,每个矩形上都有一个权值(该矩形单位面积的价值),矩形之间可能重叠,重叠部分的权值按照最大的算,最后问这n个矩形组成的图形的最大价值. 思路: 线段树扫描线 ...
- hdu1542 线段树扫描线求矩形面积的并
题意: 给你n个正方形,求出他们的所占面积有多大,重叠的部分只能算一次. 思路: 自己的第一道线段树扫描线题目,至于扫描线,最近会写一个总结,现在就不直接在这里写了,说下我的方 ...
- HDU 2795 Billboard (线段树+贪心)
HDU 2795 Billboard (线段树+贪心) 手动博客搬家:本文发表于20170822 21:30:17, 原地址https://blog.csdn.net/suncongbo/articl ...
- bzoj 1645: [Usaco2007 Open]City Horizon 城市地平线(线段树扫描线)
1645: [Usaco2007 Open]City Horizon 城市地平线 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 732 Solved: ...
最新文章
- html增加状态信息管理代码,JavaScript+HTML实现学生信息管理系统
- 你也许不知道的Vuejs - 使用ES6快乐的玩耍
- 4g通信模块怎么连接sim卡_你好eSIM,再见SIM卡
- 6.NFC之非NDEF格式
- 楼盘管理系统_教育信息化2.0,2019年校园智慧后勤管理系统五大品牌
- 计算机一级wps选择题必背知识点,计算机一级考试wps选择题专项训练
- c++ cstring 转换 char_C语言进阶之路:字符串与整数之间的转换!
- 用户登陆问题,session.invalidate销毁session
- python修改第三方库重写_对Python第三方库,再次封装
- php传奇发布站,传奇发布网站php源码
- 简述多媒体计算机的关键技术及其主要应用领域,多媒体复习题
- 控制/ 状态寄存器(RCC_CSR) 复位
- JavaScript入门,难不难你来说
- 【SearchString Algorithm Training】谭爷剪花布条
- 【Flutter】应用开发笔记
- 苹果5更新系统无服务器,苹果5手机系统更新不了出现无法检查更新怎么处理
- IOS Swift语言开发 tableView的重用以及自cell的自适应高度
- 随手记-记录一些技术点
- Problems and Solutions
- 视频去水印怎么去?这几款视频去水印工具推荐给你
热门文章
- shell题库选择题_linux操作题及答案 shell练习题
- hyperworks2017安装教程
- fileviewpro绿色免安装版
- 计算机视觉与深度学习 | 双目视觉SLAM之ORB-SLAM2的Matlab实现(完整代码)
- 数据结构与算法(C++)– 队列(Queue)
- 端计算(2)-android studio 的sdk,avd,grade及其它缓存配置
- 工业用微型计算机笔记(3)-存储单位与基本组成
- 【推荐系统】KDD2021推荐系统论文集锦
- 【学术相关】这个英文语法校正插件很赞!可以校正邮件,也可以校正论文
- 【小白学PyTorch】11.MobileNet详解及PyTorch实现