poj1151 Atlantis && cdoj 1600艾尔大停电 矩形面积并
题目:
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 23758 | Accepted: 8834 |
Description
Input
The input file is terminated by a line containing a single 0. Don't process it.
Output
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 <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring> using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=3e2+;
const int mod=1e9+; struct node
{
int f;
double l,r,y;
bool operator < (const node &ta)const
{
return y<ta.y;
}
}seg[K*];
int cover[K*];
double sum[K*],hs[K*];
void push_up(int o,int l,int r)
{
if(cover[o]) sum[o]=hs[r+]-hs[l];
else if(l==r) sum[o]=;
else sum[o]=sum[o<<]+sum[o<<|];
}
void update(int o,int l,int r,int nl,int nr,int f)
{
if(l==nl&&r==nr)
cover[o]+=f,push_up(o,l,r);
else
{
int mid=l+r>>;
if(nr<=mid) update(o<<,l,mid,nl,nr,f);
else if(nl>mid) update(o<<|,mid+,r,nl,nr,f);
else update(o<<,l,mid,nl,mid,f),update(o<<|,mid+,r,mid+,nr,f);
push_up(o,l,r);
}
}
int main(void)
{
int n,cs=;
while(scanf("%d",&n)&&n)
{
int cnt=;
double ans=;
memset(cover,,sizeof cover);
memset(sum,,sizeof sum);
for(int i=;i<=n;i++)
{
double lx,ly,rx,ry;
scanf("%lf%lf%lf%lf",&lx,&ly,&rx,&ry);
seg[cnt+].l=seg[cnt+].l=lx;
seg[cnt+].r=seg[cnt+].r=rx;
seg[cnt+].y=ry,seg[cnt+].y=ly;
seg[cnt+].f=,seg[cnt+].f=-;
hs[cnt+]=lx,hs[cnt+]=rx;
cnt+=;
}
sort(seg+,seg++n*);
sort(hs+,hs++*n);
int sz=unique(hs+,hs++n*)-hs;
for(int i=;i<*n;i++)
{
int l=lower_bound(hs+,hs+sz,seg[i].l)-hs;
int r=lower_bound(hs+,hs+sz,seg[i].r)-hs;
update(,,sz,l,r-,seg[i].f);
ans+=sum[]*(seg[i+].y-seg[i].y);
}
printf("Test case #%d\nTotal explored area: %.2f\n\n",cs++,ans);
}
return ;
}
poj1151 Atlantis && cdoj 1600艾尔大停电 矩形面积并的更多相关文章
- [POJ1151]Atlantis
[POJ1151]Atlantis 试题描述 There are several ancient Greek texts that contain descriptions of the fabled ...
- Three.js 火焰效果实现艾尔登法环动态logo 🔥
声明:本文涉及图文和模型素材仅用于个人学习.研究和欣赏,请勿二次修改.非法传播.转载.出版.商用.及进行其他获利行为. 背景 <艾尔登法环>是最近比较火的一款游戏,观察可以发现它的 Log ...
- (HDU 1542) Atlantis 矩形面积并——扫描线
n个矩形,可以重叠,求面积并. n<=100: 暴力模拟扫描线.模拟赛大水题.(n^2) 甚至网上一种“分块”:分成n^2块,每一块看是否属于一个矩形. 甚至这个题就可以这么做. n<=1 ...
- HDU 1542 Atlantis(矩形面积并)
HDU 1542 Atlantis 题目链接 题意:给定一些矩形,求面积并 思路:利用扫描线,因为这题矩形个数不多,直接暴力扫就能够了.假设数据大.就要用线段树 代码: #include <cs ...
- POJ 1151 Atlantis 线段树求矩形面积并 方法详解
第一次做线段树扫描法的题,网搜各种讲解,发现大多数都讲得太过简洁,不是太容易理解.所以自己打算写一个详细的.看完必会o(∩_∩)o 顾名思义,扫描法就是用一根想象中的线扫过所有矩形,在写代码的过程中, ...
- 【HDU 1542】Atlantis 矩形面积并(线段树,扫描法)
[题目] Atlantis Problem Description There are several ancient Greek texts that contain descriptions of ...
- 10.我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形。 请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?
我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形. 请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法? 是不是发现看不懂,哈哈:编程题就是这样,一定要归纳,手写过程: n ...
- poj-1151矩形面积并-线段树
title: poj-1151矩形面积并-线段树 date: 2018-10-30 22:35:11 tags: acm 刷题 categoties: ACM-线段树 概述 线段树问题里的另一个问题, ...
- hdu 1542&&poj 1151 Atlantis[线段树+扫描线求矩形面积的并]
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
随机推荐
- jQUery中closest和parents的主要区别是
①,前者从当前元素开始匹配寻找,后者从父元素开始匹配寻找: ②,前者逐级向上查找,直到发现匹配的元素后就停止了,后者一直向上查找直到根元素,然后把这些元素放进一个临时集合中,再用给定的选择器表达式去过 ...
- 点击一个textView里的link导航至程序内可返回的自定义webView
1,在AppDelegate.h里定义一个 id currentViewController; 在AppDelegate.m里 @implementation UIApplication (Priva ...
- Extjs6.2.0搭建项目框架
1.安装 首先你总要去官网下载ext-6.2.0-gpl.zip和安装Sencha CMD工具来管理ExtJs项目,ext-6.2.0-gpl.zip下载完成解压先放在一边,一会用到. Sencha ...
- System.Net.WebException: The operation has timed out at System.Net.HttpWebRequest.GetResponse()
System.Net.WebException: The operation has timed out at System.Net.HttpWebRequest.GetResponse() 在请求 ...
- AndroidWear开发之下载SDK[Android W/Android L]
Android L Developer Preview SDK发布了,但是天朝还是无法更新到.打开SDK Manager依旧一成不变,这时候就需要利器了. 第一步: 打开Goagent,不要说不知道什 ...
- Android 内存泄露总结(附内存检测工具)
https://segmentfault.com/a/1190000006852540 主要是分三块: 静态储存区:编译时就分配好,在程序整个运行期间都存在.它主要存放静态数据和常量. 栈区:当方法执 ...
- Python 导入与注册
背景 最近一直学习写一个POC扫描框架,但是不知道如何下手,正巧因为一些需要有朋友在研究POCSuite的实现原理,顺面蹭一些知识点,补一补Python基础的不足,为以后编写POC框架打地基. 导入 ...
- html to pdf小工具,支持evernote导出的html和firefox插件scrapbook
周末花了一天时间用wpf写了一个html转换为pdf的小工具. 已经在win7 32位 和win8 64两台机器上测试,目前基本可用,特拿来分享. 程序下载地址:http://pan.baidu.co ...
- 【BZOJ3631】松鼠的新家 树链剖分
BZOJ3631 松鼠的新家 Description 松鼠的新家是一棵树,前几天刚刚装修了新家,新家有n个房间,并且有n-1根树枝连接,每个房间都可以相互到达,且俩个房间之间的路线都是唯一的.天哪,他 ...
- centos6安装postgresql-(2)
1.Install yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-ce ...