题目:

Problem 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 file 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
0

Sample Output

Test case #1 Total explored area: 180.00

题解:

扫描线的模板题目···具体见http://blog.csdn.net/lwt36/article/details/48908031,%%%%%%%

唯一需要注意的是线段树的l到r区间其实代表的是离散化后l到r+1这一段区间·····,因为最小的单位区间表示的是一条线段···而不是一个点

代码:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<cctype>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
const int N=;
struct node
{
double l,r,h;
int op;
}line[N];
int n,m,tot,cnt[N*],T;
double ans,sum[N*],b[N];
inline bool cmp(node a,node b)
{
return a.h<b.h;
}
inline void update(int k,int l,int r)
{
if(cnt[k]) sum[k]=b[r+]-b[l];
else if(l==r) sum[k]=;
else sum[k]=sum[k*]+sum[k*+];
}
inline void modify(int k,int l,int r,int x,int y,int w)
{
if(l>=x&&r<=y)
{
cnt[k]+=w;update(k,l,r);
return;
}
int mid=(l+r)/;
if(x<=mid) modify(k*,l,mid,x,y,w);
if(y>mid) modify(k*+,mid+,r,x,y,w);
update(k,l,r);
}
int main()
{
//freopen("a.in","r",stdin);
while(true)
{
scanf("%d",&n);
if(n==) break;T++;
double X1,X2,Y1,Y2;tot=;
for(int i=;i<=n;i++)
{
scanf("%lf%lf%lf%lf",&X1,&Y1,&X2,&Y2);
line[++tot].l=X1,line[tot].r=X2,line[tot].h=Y1;line[tot].op=;b[tot]=X1;
line[++tot].l=X1,line[tot].r=X2,line[tot].h=Y2;line[tot].op=-;b[tot]=X2;
}
sort(line+,line+tot+,cmp);
sort(b+,b+tot+);
m=unique(b+,b+tot+)-b-;ans=;
memset(cnt,,sizeof(cnt));
memset(sum,,sizeof(sum));
for(int i=;i<tot;i++)
{
int Le=lower_bound(b+,b+m+,line[i].l)-b;
int Ri=lower_bound(b+,b+m+,line[i].r)-b;
if(Le<Ri) modify(,,m,Le,Ri-,line[i].op);
ans+=sum[]*(line[i+].h-line[i].h);
}
printf("Test case #%d\nTotal explored area: %.2f\n\n",T,ans);
}
return ;
}
 

最新文章

  1. Validation failed for one or more entities. See ‘EntityValidationErrors’解决方法
  2. Sql Server UniCode编码解码
  3. lucas定理,组合数学问题
  4. R语言与正态性检验
  5. jpcap
  6. skyline TerraBuilder 制作MPT方法与技巧(2)
  7. C++访问权限
  8. ASP.NET中在不同的子域中共享Session
  9. POJ1611-The Suspects-ACM
  10. 第四课 Grid Control实验 GC Agent安装(第一台机器部署) 及卸载
  11. Java随机数生成原理--转稿
  12. linux串口编程(c)
  13. Week5(10月10日):国庆之后,让我们整装期待元旦吧
  14. [LeetCode299]Bulls and Cows
  15. [笔记]我的Linux入门之路 - 04.Eclipse安装
  16. 虚拟主机导入MySQL出现Unknown character set: ‘utf8mb4’
  17. Design Mobile实现国际化
  18. C++版 - 剑指Offer 面试题45:圆圈中最后剩下的数字(约瑟夫环问题,ZOJ 1088:System Overload类似)题解
  19. Gitbash如何支持交互式命令?如何让gitbash的命令不乱码?winpty是什么鬼?干嘛用的?
  20. spring相关面试题

热门文章

  1. 香港城市大学:全球首创3D打印微型机器人技术 有望作治疗癌症用途
  2. vue2使用animate css
  3. SpringMVC-请求参数的绑定
  4. 使用EventLog组件保存Windows系统日志
  5. [JZOJ] 5837.Omeed
  6. pandas的数据联级
  7. node 文件下载到本地 (支持中文文件名)
  8. java的一些相关介绍(2013-10-07-163 写的日志迁移
  9. Python头脑风暴1
  10. 通过SWD J-Link使用J-Link RTT Viewer来查看打印日志