博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ1151 Atlantis
阅读量:7010 次
发布时间:2019-06-28

本文共 3508 字,大约阅读时间需要 11 分钟。

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 22369   Accepted: 8389

Description

There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts of the island. But unfortunately, these maps describe different regions of Atlantis. Your friend Bill has to know the total area for which maps exist. You (unwisely) volunteered to write a program that calculates this quantity.

Input

The input consists of several test cases. Each test case starts with a line containing a single integer n (1 <= n <= 100) of available maps. The n following lines describe one map each. Each of these lines contains four numbers x1;y1;x2;y2 (0 <= x1 < x2 <= 100000;0 <= y1 < y2 <= 100000), not necessarily integers. The values (x1; y1) and (x2;y2) are the coordinates of the top-left resp. bottom-right corner of the mapped area. 
The input file is terminated by a line containing a single 0. Don't process it.

Output

For each test case, your program should output one section. The first line of each section must be "Test case #k", where k is the number of the test case (starting with 1). The second one must be "Total explored area: a", where a is the total explored area (i.e. the area of the union of all rectangles in this test case), printed exact to two digits to the right of the decimal point. 
Output a blank line after each test case.

Sample Input

210 10 20 2015 15 25 25.50

Sample Output

Test case #1Total explored area: 180.00

Source

 

几何 扫描线 线段树

传说中的矩形面积并,为什么这个坑放了这么久……

想象一条垂直于x轴的直线,从左往右扫描整个区间,如果遇到一个矩形的左边线,它的有效长度就并上矩形的边线;如果遇到一个矩形的右边线,它的有效长度就减去矩形的边线(但要注意,如果减去的这部分当前被包含在多个矩形里,只需cnt--而不能减去长度)

 

1 /*by SilverN*/ 2 #include
3 #include
4 #include
5 #include
6 #include
7 using namespace std; 8 const int mxn=200010; 9 int read(){10 int x=0,f=1;char ch=getchar();11 while(ch<'0' || ch>'9'){
if(ch=='-')f=-1;ch=getchar();}12 while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}13 return x*f;14 }15 struct node{16 int w;17 double len,ri,le;18 }t[mxn<<1];19 struct line{20 double x,u,d;21 bool tp;22 }a[mxn];23 int lct=0;24 int cmp(line a,line b){
return a.x
>1;32 Build(l,mid,rt<<1);33 Build(mid,r,rt<<1|1);34 return;35 }36 void pushup(int l,int r,int rt){37 if(t[rt].w){38 t[rt].len=t[rt].ri-t[rt].le;39 return;40 }41 t[rt].len=0;42 if(l+1
=a[pos].d && a[pos].u>=t[rt].ri){49 if(a[pos].tp) t[rt].w++;else t[rt].w--;50 pushup(l,r,rt);51 return;52 }53 if(l+1==r)return;54 int mid=(l+r)>>1;55 if(a[pos].d
<<1].ri)update(l,mid,rt<<1,pos);56 if(a[pos].u>t[rt<<1|1].le)update(mid,r,rt<<1|1,pos);57 pushup(l,r,rt);58 return;59 }60 double solve(int n){61 Build(1,n,1);62 update(1,n,1,1);63 double ans=0;64 for(int i=2;i<=lct;i++){65 ans+=(a[i].x-a[i-1].x)*t[1].len;66 update(1,n,1,i);67 }68 return ans;69 }70 int n;71 int main(){72 int i,j;73 int cas=0;74 while(scanf("%d",&n) && n){75 if(cas)printf("\n");76 ++cas;77 lct=0;78 double X1,Y1,X2,Y2;79 for(i=1;i<=n;i++){80 scanf("%lf%lf%lf%lf",&X1,&Y1,&X2,&Y2);81 a[++lct].x=X1;82 a[lct].tp=1;83 a[lct].d=Y1;a[lct].u=Y2;84 y[lct]=Y1;85 a[++lct].x=X2;86 a[lct].tp=0;87 a[lct].d=Y1;a[lct].u=Y2;88 y[lct]=Y2;89 }90 sort(y+1,y+lct+1);91 sort(a+1,a+lct+1,cmp);92 double ans=solve(lct);93 printf("Test case #%d\n",cas);94 printf("Total explored area: %.2f\n",ans);95 }96 return 0;97 }

 

转载于:https://www.cnblogs.com/SilverNebula/p/6593284.html

你可能感兴趣的文章
ionic3使用echarts
查看>>
imuxsock lost 353 messages from pid 20261 due to rate-limiting 解决办法
查看>>
js如何调试,使用debug模式
查看>>
模仿黑魂锁定目标功能
查看>>
Android之Gson
查看>>
HTML5 input type 属性所有值
查看>>
java中的==、equals()、hashCode()源码分析
查看>>
安卓开发_浅谈Fragment之ListFragment
查看>>
HDU 3613 Best Reward 正反两次扩展KMP
查看>>
[AFUI]App Framework
查看>>
view类的setVisibility
查看>>
zepto.js 源码解析
查看>>
HTTP状态码大全
查看>>
使用ASP.NET Web API 2创建OData v4 终结点
查看>>
MyBatis简单的增删改查以及简单的分页查询实现
查看>>
Android快捷支付SDK Demo resultStatus={4001};memo={參数错误};result={}问题
查看>>
urllib2中自定义opener
查看>>
Hadoop快速入门
查看>>
MySql_安装及简单命令
查看>>
CSDN markdown 编辑器 第四篇 LaTex语法
查看>>