POJ 1389 Area of Simple Polygons
来源:互联网 发布:ubuntu cinnamon 编辑:程序博客网 时间:2024/06/07 18:31
扫描线
这次用的n^2算法,仍然是把x排序后扫描,每次算出两个相邻的x之间矩形的面积。当两矩形有重叠部分时把矩形升高,完全分开则分开算
#include<stdio.h>#include<algorithm>#include<math.h>using namespace std;typedef long long ll;struct square{ int x1,x2,y1,y2;};int cmp(square a,square b){ return a.y1<b.y1;}int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif // ONLINE_JUDGE square s[1005]; int x[2005]; int left[2005],right[2005]; int x1,x2,y1,y2; while(1){ int n=0; int k=0; while(1) { scanf("%d%d%d%d",&x1,&y1,&x2,&y2); if (x1==-1&&x2==-1 &&y1==-1&&y2==-1) break; s[n].x1=x1; s[n].y1=y1; s[n].x2=x2; s[n++].y2=y2; x[k++]=x1; x[k++]=x2; } if(n==0) break; sort(x,x+k); sort(s,s+n,cmp); ll area=0; int m=0; for(int i=0;i<k-1;i++){ if (x[i+1]-x[i]!=0){ left[m]=x[i]; right[m++]=x[i+1]; } } for(int i=0;i<m;i++){ int up=-1,down=-1; for(int j=0;j<n;j++){ if (s[j].x1<=left[i] && right[i]<=s[j].x2) { if (s[j].y1>up){ area+=(right[i]-left[i])*(up-down); up=s[j].y2; down=s[j].y1; } else if(s[j].y2>up){ up=s[j].y2; } } } area+=(right[i]-left[i])*(up-down); } printf("%I64d\n",area); }}
0 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(离线化+扫描线+线段树)
- 使用C语言socket实现windows pc与ftp服务器通信---socket实现ftp客户端
- 2015-2-2-工作日志-刘婉
- Page Rank (2014ICM)
- I/O多路复用
- java模式设计之单例模式
- POJ 1389 Area of Simple Polygons
- USART打印消息--实现类似printf()的函数
- Verdi2013.07和nLint2011.10安装及启动license
- 单行道行车模拟(元胞自动机)——greatji1994
- iOS库--.a与.framework
- 2.2日志
- OpenFire源码学习之十一:连接管理(下)
- 2015-2-2工作日志-王亮晶
- Python Django框架根据模型不能新建表