POJ 1151 Atlantis
来源:互联网 发布:php credits是什么 编辑:程序博客网 时间:2024/06/05 11:28
简单的扫描线
把所有的矩形分割成一个个小矩形,再一点点加起来
#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif // ONLINE_JUDGE int n,xy[205][205]; double s[105][4];//矩形 double x[205],y[205]; int cas=1; while(scanf("%d",&n),n) { int k=0; memset(xy,0,sizeof(xy)); for(int i=0;i<n;i++) { scanf("%lf%lf%lf%lf",&s[i][0],&s[i][1],&s[i][2],&s[i][3]); x[k]=s[i][0]; y[k++]=s[i][1]; x[k]=s[i][2]; y[k++]=s[i][3]; } sort(x,x+2*n); sort(y,y+2*n); for(int i=0;i<n;i++) { int x1,x2,y1,y2; for(x1=0;x1<2*n;x1++) { if (x[x1]==s[i][0]) break; } for(x2=0;x2<2*n;x2++) { if (x[x2]==s[i][2]) break; } for(y1=0;y1<2*n;y1++) { if (y[y1]==s[i][1]) break; } for(y2=0;y2<2*n;y2++) { if (y[y2]==s[i][3]) break; } for(int j=x1;j<x2;j++) { for(int k=y1;k<y2;k++) { xy[j][k]=1; } } } double area=0; for(int i=0;i<2*n;i++){ for(int j=0;j<2*n;j++) { area+=xy[i][j]*(x[i+1]-x[i])*(y[j+1]-y[j]); } } printf("Test case #%d\n",cas++); printf("Total explored area: %.2f\n\n",area); }}
0 0
- POJ 1151 Atlantis
- poj 1151 Atlantis
- poj 1151 Atlantis
- poj 1151 Atlantis
- poj 1151 Atlantis
- POJ 1151 Atlantis
- poj 1151 Atlantis
- POJ 1151 Atlantis
- NYOJ186 Atlantis & POJ 1151
- POJ-1151-Atlantis
- POJ 1151: Atlantis
- poj 1151 Atlantis
- poj 1151 Atlantis
- POJ 1151 Atlantis
- poj 1151 Atlantis
- poj-1151-Atlantis
- POJ 1151 Atlantis
- POJ 1151 Atlantis
- 异常体系与异常处理
- iOS可执行文件瘦身方法
- 信号signal
- linux下判断文件和目录是否存在[总结]
- 50个Android开发人员必备UI效果源码
- POJ 1151 Atlantis
- iOS使用矢量图的总结
- C/C++/JAVA中short,int,long等整型表示范围的比较
- Android App 性能优化实践
- NYOJ 220 (红黑树--模拟)
- OpenStack对象存储——Swift
- 监听各个GUI控件的交互事件。
- stm32 使用printf 输出当前信息
- Android学习笔记