hdu 1542 线段树+扫描线+离散化~~
来源:互联网 发布:软件销售分成比例 编辑:程序博客网 时间:2024/04/29 04:19
第一道额~~理解了好久~
思路基本都是网上的~
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <map>#define lson pos<<1#define rson pos<<1|1using namespace std;const int MAXN=1000005;struct line{ double l,r,h; int f; line(double a=0,double b=0,double c=0,int d=0): l(a),r(b),h(c),f(d){}};line a[MAXN];double x[MAXN];bool cmp(const line &lhs,const line &rhs){ return lhs.h<rhs.h;}struct node{ int l,r; double sum; int cover; int mid() { return (l+r)>>1; }};node tree[MAXN*4];void pushup(int pos);void build(int l,int r,int pos){ tree[pos].l=l; tree[pos].r=r; if(l==r) { tree[pos].sum=0; tree[pos].cover=0; return ; } int mid=tree[pos].mid(); build(l,mid,lson); build(mid+1,r,rson); tree[pos].cover=0; tree[pos].sum=0;}void pushup(int pos){ if(tree[pos].cover) { int l=tree[pos].l; int r=tree[pos].r+1; tree[pos].sum=x[r]-x[l]; } else if(tree[pos].l==tree[pos].r) tree[pos].sum=0; else tree[pos].sum=tree[lson].sum+tree[rson].sum;}void update(int l,int r,int f,int pos){ if(l==tree[pos].l&&r==tree[pos].r) { tree[pos].cover+=f; pushup(pos); return ; } int mid=tree[pos].mid(); if(r<=mid) update(l,r,f,lson); else if(l>mid) update(l,r,f,rson); else { update(l,mid,f,lson); update(mid+1,r,f,rson); } pushup(pos);}int main(){ int n; int cas=0; while(scanf("%d",&n),n) { int i; cas++; map<double,int> mp; int k=0; int k1=1; for(i=0;i<n;i++) { double x1,y1,x2,y2; scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); a[k++]=line(x1,x2,y1,1); a[k++]=line(x1,x2,y2,-1); if(mp[x1]==0) { mp[x1]=k1; x[k1]=x1; k1++; } if(mp[x2]==0) { mp[x2]=k1; x[k1]=x2; k1++; } } build(1,k1-1,1); sort(a,a+k,cmp); sort(x+1,x+k1); for(i=1;i<k1;i++) mp[x[i]]=i; double ans=0; for(i=0;i<k-1;i++) { int l=mp[a[i].l]; int r=mp[a[i].r]-1; update(l,r,a[i].f,1); ans+=(a[i+1].h-a[i].h)*tree[1].sum; } printf("Test case #%d\n",cas); printf("Total explored area: %.2lf\n\n",ans); } return 0;}
- hdu 1542 线段树+扫描线+离散化~~
- HDU 1542 Atlantis(线段树+离散化+扫描线)
- hdu 1542 Atlantis (线段树+离散化+扫描线)
- HDU 1542 Atlantis [离散化 + 扫描线 + 线段树]
- HDU 1542 Atlantis (线段树 + 扫描线 + 离散化)
- HDU 1542 Atlantis (线段树 +离散化+ 扫描线)
- HDU 1542 Atlantis(线段树,离散化,扫描线)
- HDU 1542 Atlantis (线段树+离散化+扫描线)
- hdu 1542 Atlantis (线段树,离散化+扫描线)
- HDU 1542 Atlantis 线段树 (扫描线 + 离散化)
- 线段树+扫描线+离散化解poj1151 hdu 1542 ( Atlantis )
- hdu 4007 Dave(线段树+离散化+扫描线)
- hdu 4419 (线段树 + 扫描线 + 离散化)
- poj 1177 / hdu 1828 线段树 离散化 扫描线
- hdu 4419 线段树 离散化 扫描线
- 离散化 + 扫描线 + 线段树 hdu 4007
- HDU 4419 Colourful Rectangle --离散化+线段树扫描线
- hdu 5091 Beam Cannon 离散化+扫描线+线段树
- CodeForces 126B - Password 利用KMP
- 巴哥奔
- 仿百度文库
- UVA——10139(数论)(挑战编程题目)
- “十天一本书”之15—《公司是最好的学校》感慨
- hdu 1542 线段树+扫描线+离散化~~
- 黑马程序员——Java学习笔记(七)
- python文件锁
- 2013腾讯编程马拉松初赛第一场(3月21日) 小Q系列故事——电梯里的爱情
- 为学日益,为道日损
- POJ 1285 - Combinations, Once Again 泛化背包
- MySql 时间日期函数
- 让javadoc 生成的api以目录树的方式查看
- 解决windows7客户端无法访问Samba服务器的故障