poj 1151 Atlantis 纯矩形面积并
来源:互联网 发布:三国志13武将数据修改 编辑:程序博客网 时间:2024/06/07 22:53
以端点建树,所以对于l,r 它的子区间为l,mid 和mid,r
#include<algorithm>#include<iostream>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<vector>#include<queue>#include<cmath>#include<math.h>using namespace std;#define inf 0x3f3f3f3fconst int dir[4][2]={0,1,0,-1,1,0,-1,0};#define maxn 205struct Tree{int l,r;//左右端点int c;//覆盖情况double cnt,lf,rf;//cnt为长度,lf为实际左坐标,rf为实际右坐标}tree[maxn*4];struct Line{double x,y1,y2;int f;//直线的标记}line[maxn];bool cmp(Line a,Line b)//sort排序的函数{ return a.x < b.x;} double y[maxn];//记录y坐标void build(int l,int r,int root){tree[root].l=l;tree[root].r=r;tree[root].c=tree[root].cnt=0;tree[root].lf=y[l];tree[root].rf=y[r];if(l+1==r)return;int mid=(l+r)>>1;build(l,mid,root<<1);build(mid,r,root<<1|1);}void calen(int root){if(tree[root].c>0){tree[root].cnt=tree[root].rf-tree[root].lf;return ;}if(tree[root].l+1==tree[root].r) tree[root].cnt=0;else tree[root].cnt=tree[root<<1].cnt+tree[root<<1|1].cnt;}void update(int root,struct Line e){if(e.y1==tree[root].lf&&e.y2==tree[root].rf){tree[root].c+=e.f;calen(root);return;}if(e.y2<=tree[root<<1].rf)update(root<<1,e);else if(e.y1>=tree[root<<1|1].lf)update(root<<1|1,e);else{Line tmp=e;tmp.y2=tree[root<<1].rf;update(root<<1,tmp);tmp=e;tmp.y1=tree[root<<1|1].lf;update(root<<1|1,tmp);}calen(root);}int main(){int i,j;int n,k,R=0;double x1,y1,x2,y2;while(scanf("%d",&n)!=EOF&&n!=0){R++;k=1;for(i=1;i<=n;i++) { scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); line[k].x=x1; line[k].y1=y1; line[k].y2=y2; line[k].f=1; y[k]=y1; k++; line[k].x=x2; line[k].y1=y1; line[k].y2=y2; line[k].f=-1; y[k]=y2; k++; }k--;sort(line+1,line+k+1,cmp); sort(y+1,y+k+1);int mm;mm=unique(y+1,y+1+k)-y-1;build(1,mm,1);update(1,line[1]);double ans=0;for(i=2;i<=k;i++){ans+=tree[1].cnt*(line[i].x-line[i-1].x);update(1,line[i]);}printf("Test case #%d\nTotal explored area: %.2lf\n\n",R,ans);}return 0;}
0 0
- poj 1151 Atlantis 纯矩形面积并
- 矩形面积并 poj 1151Atlantis
- 矩形面积并 POJ Atlantis
- POJ 1151 Atlantis 线段树/矩形面积并
- Hdu 1542/ POj 1151 Atlantis 线段树+矩形面积并
- POJ 1151 Atlantis (线段树求矩形面积并)
- zoj 1128 || poj 1151 Atlantis(线段树求矩形面积并)
- poj 1151 hdu 1542 hoj1119 Atlantis 线段树扫描线求矩形面积并
- poj 1151 Atlantis / hdu 1542 线段树扫描线 矩形面积并
- poj 1151 Atlantis(矩形面积并,线段树+离散化)
- 【线段树 + 离散化 + 扫描线】poj 1151 Atlantis 矩形面积并
- POJ 1151 / HDU 1542 Atlantis 线段树求矩形面积并
- POJ 1151 Atlantis (线段树+扫描线 求矩形面积并)
- POJ-1151-Atlantis-求矩形面积并(线段树+扫描线)
- HDU-1542/POJ-1151 Atlantis(矩形并面积--线段树+离散化)
- POJ 1151 Atlantis 线段树面积并
- poj 1151 线段树+扫描线(Atlantis矩形面积)
- hdu1542 Atlantis(矩形面积并)
- DBus 入门与应用 -- DBus 的 C 编程接口
- hdu 4493 Tutor
- 提高代码编码的效率,习惯很重要!
- Fatal error: Call-time pass-by-reference has been removed in
- hdu 1753 高精度加法,带小数点
- poj 1151 Atlantis 纯矩形面积并
- 关于java中如何判断ResultSet是否为空的问题
- Next Permutation
- 生态文明要求人们要主动改变以往的观念,用新的思维方式和实践方法推动社会向前发展
- DBus 入门与应用--基本概念 下(C API 级别的使用观点)
- SAS 导出文件
- 排序N个比N^7小的数,要求的算法是O(n)
- 如何让浏览器正确识别网页编码
- 变焦与对焦(转自csdn)