TOJ2712: Atlantis
小数据求面积并
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
Source
这个直接用了二分查询,但是复杂度还是蛮高的
#include<bits/stdc++.h>
using namespace std;
const int N=;
const double eps=1e-;
int n,vis[N],t;
double has[N];
struct line
{
double l,r,y;
int f;
line(){}
line(double l,double r,double y,int f):l(l),r(r),y(y),f(f){}
}L[N];
bool cmp(line a,line b)
{
return a.y<b.y;
}
int get(double x)
{
return lower_bound(has,has+t,x)-has;
}
int main()
{
int ca=,i,j;
double x1,y1,x2,y2;
while(scanf("%d",&n),n)
{
t=;
memset(vis,,sizeof vis);
for(i=; i<n; i++)
{
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
L[t]=line(x1,x2,y1,),has[t++]=x1;
L[t]=line(x1,x2,y2,-),has[t++]=x2;
}
n*=;
sort(L,L+n,cmp);
sort(has,has+t);
t=;
for(i=;i<n;i++)
if(fabs(has[i]-has[i-])>eps)has[t++]=has[i];
double res=;
for(i=; i<n; i++)
{
int l=get(L[i].l),r=get(L[i].r);
double len=;
for(j=;j<t-;j++)
if(vis[j]>)len+=has[j+]-has[j];
if(i)res+=len*(L[i].y-L[i-].y);
for(j=l;j<r;j++)vis[j]+=L[i].f;
}
printf("Test case #%d\nTotal explored area: %.2f\n\n",++ca,res);
}
return ;
}
TOJ2712: Atlantis的更多相关文章
- [POJ1151]Atlantis
[POJ1151]Atlantis 试题描述 There are several ancient Greek texts that contain descriptions of the fabled ...
- 线段树---Atlantis
题目网址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=110064#problem/A Description There are se ...
- hdu 1542 Atlantis(线段树,扫描线)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- 【POJ】1151 Atlantis(线段树)
http://poj.org/problem?id=1151 经典矩形面积并吧.....很简单我就不说了... 有个很神的地方,我脑残没想到: 将线段变成点啊QAQ这样方便计算了啊 还有个很坑的地方, ...
- HDU 1542 Atlantis(线段树扫描线+离散化求面积的并)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- POJ 1542 Atlantis(线段树 面积 并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 参考网址:http://blog.csdn.net/sunmenggmail/article/d ...
- [POJ 1151] Atlantis
一样的题:HDU 1542 Atlantis Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18148 Accepted ...
- 【HDU 1542】Atlantis 矩形面积并(线段树,扫描法)
[题目] Atlantis Problem Description There are several ancient Greek texts that contain descriptions of ...
- 【POJ1151】【扫描线+线段树】Atlantis
Description There are several ancient Greek texts that contain descriptions of the fabled island Atl ...
随机推荐
- 真正的S2b其实是S2b2c
本文转自阿里参谋长曾鸣:真正的S2b其实是S2b2c! 在<在未来五年,S2b是最有可能领先的商业模式>这篇文章发表之后,曾鸣书院收到了非常多的反馈,看到很多实践和思考. 在这篇文章中,曾 ...
- <转>Java 高并发综合
并发模型 悲观锁和乐观锁的理解及如何实现,有哪些实现方式? 悲观锁 悲观锁假设最坏的情况(如果你不锁门,那么捣蛋鬼就会闯入并搞得一团糟),并且只有在确保其他线程不会干扰(通过获取正确的锁)的情况下才能 ...
- (四)我的JavaScript系列:原型链
夜深风竹敲秋韵,万叶千声皆是恨. 原型链对于JavaScript来说是个很核心的概念.JavaScript不是基于类模板的面向对象语言:反而,它的面向对象机制是基于原型的.我们不可能说某个对象属于什么 ...
- HoloLens | 世界的每一次变化,其实都提前打好了招呼
新年,对灯发誓——不说老话,说新鲜事. 佛经上说:世间唯一永恒不变的,就是永远在变化. 130年前(说好的不说老话呢),世界上第一辆汽车在德国发出第一声轰鸣,世界变了: 现在,汽车已遍及世界,颜值.性 ...
- 使用Python+selenium过程中所需安装的库和软件
一.下载地址: 1.setuptools:https://pypi.python.org/pypi/setuptools#downloads 中file对应的后缀为zip的软件 pip:https:/ ...
- HTML页面右键事件
<script type="text/javascript"> <!-- document.onmousedown = function (e) { var e ...
- windows server 2008 R2 的 FTP 防火墙的正确配置方法
存在问题 FTP搭建完成后,仅本机可以访问,其他机器无法访问. 解决方案 这时,将C:\Windows\System32\svchost.exe添加到例外即可正常访问,如下图所示.将20及21端口添加 ...
- 程序员的智囊库系列之3--分布式文件系统(Distributed file systems)
程序员的智囊库系列之3--分布式文件系统(Distributed file systems) 这是程序员的智囊库系列的第三篇文章.上一篇文章本来打算介绍几个搭建网站的框架,但由于这部分的内容较多,还需 ...
- groupmod - 修 改 群 组
总览 SYNOPSIS groupmod [-g gid [-o]] [-n group_name ] group 描述 DESCRIPTION groupmod 命 令 会 参 照 你 命 令 列 ...
- 一、git提交代码步骤
git add . //添加到本地缓存区 git commit -m '备注 ' //提交代码到本地仓库 git push //将本地代码推送到develop分支上 git checkout m ...