(codevs 3044 矩形面积求并)<可以不用线段树>
来源:互联网 发布:网络构架 编辑:程序博客网 时间:2024/05/17 20:32
传送门
Solution
听说这个题
有
有
竟然
不管反正我考场写挂QAQ
虽然我对这个题还是理(wan)解(quan)很(bu)深(dong)的,但我还是要安利一下hzwer的博客,但是他的代码在codevs上好像wa了。。。雾
说一下细节:
线段树每个节点存的是这个点到下一个点的区间是否被覆盖
另外还有一个,这个题数据范围是100,理论上开200多的数组就可以,但事实上要600多才行。。。
Code
不要手残变量开成int
// by spli#include<cstring>#include<algorithm>#include<iostream>#include<cstdio>#include<ctime>#include<queue>#include<cstdlib>#include<map>#include<stack>#include<cmath>using namespace std;const int N=310;int n;struct node{ double x1,x2,h,f;}p[N<<1];double ha[N<<1];int col[N<<1];double s[N<<1];bool cmp(node a,node b){ return a.h<b.h;}void pushup(int pos,int L,int R){ if(col[pos]) s[pos]=ha[R+1]-ha[L]; else if(L==R) s[pos]=0; else s[pos]=s[pos<<1]+s[pos<<1|1];}void update(int pos,int L,int R,int ll,int rr,int f){ if(ll>R||L>rr) return; if(ll<=L&&rr>=R){ col[pos]+=f; pushup(pos,L,R); return; } int mid=(L+R)>>1; update(pos<<1,L,mid,ll,rr,f); update(pos<<1|1,mid+1,R,ll,rr,f); pushup(pos,L,R);}void work(){ memset(s,0,sizeof(s)); memset(ha,0,sizeof(ha)); memset(col,0,sizeof(col)); double x1,x2,y1,y2; for(int i=1;i<=n;++i){ scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); p[i*2-1]=(node){x1,x2,y1,1}; p[i*2]=(node){x1,x2,y2,-1}; ha[i*2-1]=x1; ha[i*2]=x2; } sort(p+1,p+1+2*n,cmp); sort(ha+1,ha+1+2*n); int ll,rr; double ans=0; for(int i=1;i<=2*n;++i){ ll=lower_bound(ha+1,ha+1+2*n,p[i].x1)-ha; rr=lower_bound(ha+1,ha+1+2*n,p[i].x2)-ha-1; if(ll<=rr) update(1,1,2*n,ll,rr,p[i].f); ans+=s[1]*(p[i+1].h-p[i].h); } printf("%.2lf\n",ans); return;}int main(){ while(scanf("%d",&n)&&n) work(); return 0;}
阅读全文
0 0
- (codevs 3044 矩形面积求并)<可以不用线段树>
- Codevs 题目3044 矩形面积求并(线段树+扫描线+离散化)
- 【codevs 3044】 矩形面积求并 【线段树 扫描线 离散化】
- [CODEVS 3044] 矩形面积求并
- [Codevs] 3044 矩形面积求并(离散化)
- 线段树 求矩形并 面积
- hdu3265(线段树求矩形面积并)
- 线段树-矩形面积求并
- HDU 1542 Atlantis(线段树求矩形面积并)
- 求矩形并的面积(线段树)【模板】
- HDU 1542 Atlantis(线段树求矩形面积并)
- POJ 1389 求矩形面积并(线段树)
- hdu 1542 (线段树求矩形面积并)
- codevs 3044_矩形面积求并_离散
- Codevs P3044矩形面积求并
- 【codevs 3044】【HDU 1542】【poj 1151】矩形面积并 线段树+‘扫描线’
- codevs 3044 线段树+离散化+扫描线 (矩形面积并
- hdu 1542(线段树 求矩形面积并)Atlantis
- 一头坑进Redis之常见redis.conf配置介绍
- Vivado下生成及烧写MCS文件
- 练习14
- centos6安装Apache服务器
- Hihocoder 1430 Problem I. A Boring Problem (二项式定理
- (codevs 3044 矩形面积求并)<可以不用线段树>
- 利用KNN算法实现手写体数字的识别
- GPIO
- Spark基础-Scala条件判断和循环
- 简易的多组数据题模板
- codeforces #428 Div.2 B. Game of the Rows 贪心、思维
- Codeforces 839D Winter is here
- composer简介
- JAVA之面向对象