【poj1151】【离散化】Atlantis
来源:互联网 发布:xcc mixer软件 编辑:程序博客网 时间:2024/06/02 18:58
Atlantis
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 21743 Accepted: 8184Description
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
2
10 10 20 20
15 15 25 25.5
0Sample Output
Test case #1
Total explored area: 180.00Source
Mid-Central European Regional Contest 2000
题目大意就是说给你n个矩形,然后让你求面积
然后只有100个矩阵,但是大小很大,而且是实数,所以要离散,然后扫面线求出面积
我比较懒。不想写那么多字,就推荐你们看这个:http://blog.csdn.net/youngyangyang04/article/details/7787693
然后差不多就这样,我的代码:
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<set>#include<map>#include<queue>#include<algorithm>#include<vector>#include<cstdlib>#include<cmath>#include<ctime>#include<stack>#define INF 2100000000#define ll long long#define clr(x) memset(x,0,sizeof(x))#define clrmax(x) memset(x,127,sizeof(x))using namespace std;inline int read(){ char c; int ret=0; while(!(c>='0'&&c<='9')) c=getchar(); while(c>='0'&&c<='9') { ret=(c-'0')+(ret<<1)+(ret<<3); c=getchar(); } return ret;}#define M 10005struct node{ double x,y1,y2; int flag,no;}a[M*2];#define x(y) a[y].x#define y1(x) a[x].y1#define y2(x) a[x].y2#define flag(x) a[x].flag#define no(x) a[x].nostruct tree2{ tree2 *lson,*rson; int s,bo; double len,l,r;}*root,dizhi[M];int T;const double eps=1E-8;int n,t,vis[M],cnt;double t1[M],t2[M],t3[M],t4[M];double y[M],ans;bool com(node a,node b){ return a.x<b.x;}bool equal(double a,double b){ return (a+eps>=b&&a-eps<=b);}void bulid(tree2 *tree,int l,int r){ tree->l=y[l]; tree->r=y[r]; tree->s=tree->len=0; if(r-l==1) { tree->bo=1; return ; } int mid=(l+r)>>1; tree->lson=&dizhi[T++]; tree->rson=&dizhi[T++]; bulid(tree->lson,l,mid); bulid(tree->rson,mid,r);}void update(tree2 *&tree){ if(tree->s>0) { tree->len=tree->r-tree->l; return ; } if(tree->bo) { tree->len=0; return ; } tree->len=tree->lson->len+tree->rson->len;}void change(tree2 *tree,int l,int r,node x){ if(equal(x.y1,x.y2))return ; if(equal(tree->l,x.y1)&&equal(tree->r,x.y2)) { tree->s+=x.flag; update(tree); return ; } int mid=(l+r)>>1; if(x.y2<tree->lson->r)change(tree->lson,l,mid,x); else if(x.y1>tree->rson->l)change(tree->rson,mid,r,x); else { node temp=x; temp.y2=tree->lson->r; change(tree->lson,l,mid,temp); temp=x; temp.y1=tree->rson->l; change(tree->rson,mid,r,temp); } update(tree);}int main(){ freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); while(cin>>n) { cnt++; if(n==0)return 0; clr(a);clr(vis);ans=0;t=0; clr(dizhi);T=0; root=&dizhi[T++]; for(int i=1;i<=n;i++) { double x1,x2,y1,y2; scanf("%lf%lf%lf%lf",&t1[i],&t2[i],&t3[i],&t4[i]); x1=t1[i];x2=t3[i]; y1=t2[i];y2=t4[i]; y[++t]=y1; x(t)=x1;y1(t)=y1;y2(t)=y2;flag(t)=1;no(t)=i; y[++t]=y2; x(t)=x2;y1(t)=y1;y2(t)=y2;flag(t)=-1;no(t)=i; } sort(a+1,a+2*n+1,com); sort(y+1,y+2*n+1); bulid(root,1,2*n); double last=x(1); vis[no(1)]=flag(1); for(int i=1;i<=2*n;i++) { ans+=(x(i)-x(i-1))*root->len; change(root,1,2*n,a[i]); } printf("Test case #%d\nTotal explored area: %.2f\n\n",cnt,ans); } return 0;}
大概就是这个样子,如果有什么问题,或错误,请在评论区提出,谢谢。
- POJ1151 Atlantis [离散化]
- 【poj1151】【离散化】Atlantis
- POJ1151--Atlantis(离散化+扫描线)
- poj1151——Atlantis(离散化+扫描线)
- poj1151 Atlantis 扫描线+线段树+离散化
- poj1151-- Atlantis(线段树+离散化+扫描线)
- poj1151 & hdu1542 Atlantis(扫描线+离散化+线段树)
- poj1151 Atlantis(线段树+离散化+扫描线)
- POJ1151 Atlantis 线段树+扫描线(离散化)
- 【POJ1151】Atlantis-线段树+离散化+扫描线
- POJ1151 (HDU 1542) Atlantis【矩形面积并,线段树+离散化+扫描线模板】
- POJ1151 Atlantis(线段树,扫描线,离散化,矩形面积并)
- poj1151 Atlantis(线段树+扫描线+离散化,求矩形面积并)
- POJ1151 离散化
- poj1151 Atlantis
- POJ1151-Atlantis
- poj1151 Atlantis
- poj1151 Atlantis
- Javascript原型和原型链图解
- 一个毕业生的毕业经历
- shell脚本之seq命令
- RESTful风格(使用Ajax+Spring MVC框架实现)
- Activity生命周期和启动模式
- 【poj1151】【离散化】Atlantis
- Android ListView、GridView中getChildAt返回值不正确的问题
- [心得]基于Flask技术的web博客开发总结
- wget 命令用法详解
- js 读取input[type=file]
- Android OpenGLES2.0(七)——着色器语言GLSL
- 菜鸟们掌握这些,自增自减再也不用混淆啦!
- Javascript:通用不间断滚动&省、市、地区联动选择JS封装类
- Android apk应用包名获取工具,以及源码