poj1151 Atlantis
来源:互联网 发布:php配置环境工具 编辑:程序博客网 时间:2024/05/29 21:18
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 18723 Accepted: 7105
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.
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.
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
Mid-Central European Regional Contest 2000
以前线段树的写法十分没效率……写了个更屌的
#include<map>#include<string>#include<cstring>#include<cstdio>#include<cstdlib>#include<cmath>#include<queue>#include<vector>#include<iostream>#include<algorithm>#include<bitset>#include<climits>#include<list>#include<iomanip>#include<stack>#include<set>using namespace std;double hs[210];struct Tree{int l,r,num;double val;}tree[200<<2];void create(int l,int r,int k){tree[k].l=l;tree[k].r=r;tree[k].val=0;tree[k].num=0;if(l+1==r)return;int m=l+r>>1;create(l,m,k<<1);create(m,r,k<<1|1);}void update(int l,int r,int k,int flag){if(tree[k].l==l&&tree[k].r==r){tree[k].num+=flag;if(tree[k].num==0)tree[k].val=l+1==r?0:tree[k<<1].val+tree[k<<1|1].val;elsetree[k].val=hs[r]-hs[l];return;}int m=tree[k].l+tree[k].r>>1;if(r<=m)update(l,r,k<<1,flag);else if(l>=m)update(l,r,k<<1|1,flag);else{update(l,m,k<<1,flag);update(m,r,k<<1|1,flag);}if(tree[k].num==0)tree[k].val=tree[k<<1].val+tree[k<<1|1].val;}struct Seg{int flag;double l,r,y;bool operator <(Seg one)const{return y<one.y;}}seg[210];int main(){int n,cs=0;while(cin>>n&&n!=0){vector<double>box;for(int i=0;i<n;i++){double x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2;seg[i<<1].l=seg[i<<1|1].l=x1;seg[i<<1].r=seg[i<<1|1].r=x2;seg[i<<1].y=y1;seg[i<<1|1].y=y2;seg[i<<1].flag=1;seg[i<<1|1].flag=-1;box.push_back(x1);box.push_back(x2);}sort(box.begin(),box.end());box.erase(unique(box.begin(),box.end()),box.end());for(int i=0;i<box.size();i++)hs[i+1]=box[i];n*=2;sort(seg,seg+n);double ans=0;create(1,box.size(),1);for(int i=0;i<n;i++){int l=1+lower_bound(box.begin(),box.end(),seg[i].l)-box.begin();int r=1+lower_bound(box.begin(),box.end(),seg[i].r)-box.begin();if(i!=n-1){update(l,r,1,seg[i].flag);ans+=tree[1].val*(seg[i+1].y-seg[i].y);}}printf("Test case #%d\n",++cs);printf("Total explored area: %.2f\n\n",ans);}}
0 0
- poj1151 Atlantis
- POJ1151-Atlantis
- poj1151 Atlantis
- poj1151 Atlantis
- poj1151——Atlantis
- POJ1151 Atlantis [离散化]
- poj1151--Atlantis--扫描线
- POJ1151 Atlantis 【扫描线】
- HDU1542&&POJ1151-Atlantis
- 【poj1151】【离散化】Atlantis
- [POJ1151] Atlantis - 矩形切割
- POJ1151 Atlantis扫描线求矩形面积
- poj1151 Atlantis(hh版 扫描线)
- POJ1151--Atlantis(离散化+扫描线)
- POJ1151 HDU1542 CODEVS3044 Atlantis 题解&代码
- Atlantis poj1151 扫描线+线段树
- [POJ1151]Atlantis(扫描线+线段树)
- poj1151 Atlantis(线段树+扫描线)
- XML文件的解析和生成(DOM)
- 第十一周上机实践项目0——是春哥啊
- Hadoop2.4 MapReduce本地调试
- 清除浮动常用方法
- asp.net 学习之路之chart控件
- poj1151 Atlantis
- 一点点开始熟悉C++11的新特性
- CSS定位——position、float小结
- hdu 5229 ZCC loving string
- Spring+SpringMVC+Mybatis+Mysql整合实例
- Java异常处理
- C++自增操作符你真的懂?
- 第2章:文件I/O
- 基于VHDL的层次化设计:异步清零和同步使能4位十六进制加法计数器和七段显示译码器的元件例化实现