POJ-1389-Area of Simple Polygons
来源:互联网 发布:java基础入门课后笔记 编辑:程序博客网 时间:2024/05/17 22:22
这个题跟POJ-1151很像,基本上差不多的,这个题还没有了浮点数的运算。
思路:跟1151一样的,同样是扫描线+线段树+离散化
代码:
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int maxn=1111;struct node{ int x; int y1; int y2; int flag; bool operator <(const node &a)const {return x<a.x; }}p[maxn*2];struct Tree{ int l; int r; int len; int val;}t[maxn*4];int n,m,py[maxn*2],a[maxn*2];void Build(int L,int R,int index){ t[index].l=L; t[index].r=R; t[index].len=t[index].val=0; if(L==R-1)return; int mid=(L+R)>>1; Build(L,mid,index<<1); Build(mid,R,index<<1|1);}int Search(int val){ int l=1,r=m; while(l<=r) {int mid=(l+r)>>1;if(a[mid]==val) return mid;if(a[mid]<val) l=mid+1;else r=mid-1; } return -1;}void Callen(int index){ if(t[index].val>0)t[index].len=a[t[index].r]-a[t[index].l]; else if(t[index].l+1==t[index].r)t[index].len=0; elset[index].len=t[index<<1].len+t[index<<1|1].len;}void Update(int l,int r,int val,int index){ if(t[index].l==l&&t[index].r==r) {t[index].val+=val;Callen(index);return; } int mid=(t[index].l+t[index].r)>>1; if(r<=mid)Update(l,r,val,index<<1); else if(l>=mid)Update(l,r,val,index<<1|1); else {Update(l,mid,val,index<<1);Update(mid,r,val,index<<1|1); } Callen(index);}int main(){ int x1,y1,x2,y2; while(scanf("%d%d%d%d",&x1,&y1,&x2,&y2)!=EOF) {if(x1==-1) break;int cou=1;p[cou].x=x1;p[cou].y1=y1;p[cou].y2=y2;p[cou].flag=1;py[cou++]=y1;p[cou].x=x2;p[cou].y1=y1;p[cou].y2=y2;p[cou].flag=-1;py[cou++]=y2;while(1){ scanf("%d%d%d%d",&x1,&y1,&x2,&y2); if(x1==-1)break; p[cou].x=x1; p[cou].y1=y1; p[cou].y2=y2; p[cou].flag=1; py[cou++]=y1; p[cou].x=x2; p[cou].y1=y1; p[cou].y2=y2; p[cou].flag=-1; py[cou++]=y2;}cou--;sort(p+1,p+cou+1);sort(py+1,py+cou+1);m=1;a[1]=py[1];for(int i=2;i<=cou;i++) if(py[i]!=py[i-1])a[++m]=py[i];Build(1,m,1);int ans=0;for(int i=1;i<cou;i++){ int a=Search(p[i].y1); int b=Search(p[i].y2); Update(a,b,p[i].flag,1); ans+=t[1].len*(p[i+1].x-p[i].x);}printf("%d\n",ans); } return 0;}
- poj 1389 Area of Simple Polygons
- poj 1389 Area of Simple Polygons
- POJ-1389-Area of Simple Polygons
- poj 1389 Area of Simple Polygons
- POJ 1389 Area of Simple Polygons
- POJ 1389 Area of Simple Polygons .
- POJ 1389 Area of Simple Polygons 笔记
- poj 1389 Area of Simple Polygons(线段树做法)
- POJ 1389 Area of Simple Polygons(扫描线)
- poj 1389Area of Simple Polygons(矩形面积并)
- POJ 1389 Area of Simple Polygons 线段树 扫描线
- PKU 1389 Area of Simple Polygons
- POJ1389-Area of Simple Polygons
- POJ1389[Area of Simple Polygons]
- poj1389 Area of Simple Polygons
- poj 1389 Area of Simple Polygons 线段树扫面线,和1151一样的嘛
- POJ 1389 Area of Simple Polygons 线段树求矩形面积
- poj - 1389 - Area of Simple Polygons(离线化+扫描线+线段树)
- 在Tomcat中配置虚拟主机
- Objective-C中的protocol用法
- 一些看英语文档的笔记
- 实时数据库系统及其特征
- VS 的makefile工程
- POJ-1389-Area of Simple Polygons
- hdu2187 悼念512汶川大地震遇难同胞——老人是真饿了 (贪心)
- ext tabpanel background image Self Adaptive
- java导入与导出excel,兼容excel2003以及excel2007
- 选择最佳微控制器的10个步骤
- malloc()和free()里的学问
- c语言swap(a,b)值交换的4种实现方…
- using namespace std 详解
- strlen