HDU1542 Atlantis(矩形面积并)
#pragma warning (disable:4996)
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#define maxn 150
using namespace std; int n;
struct Segment
{
double l, r, x;
int li, ri;
bool isleft;
bool operator < (const Segment &b) const{
return x < b.x;
}
}s[maxn*3]; int top;
double ydis[800];
int ytop = 0; struct Node
{
int cov;
int l, r;
double len;
}N[3000]; void build(int i, int L, int R)
{
N[i].cov = 0;
N[i].l = L; N[i].r = R;
N[i].len = ydis[R] - ydis[L];
if (N[i].r-N[i].l<=1){
return;
}
int M = (L + R) >> 1;
build(i << 1, L, M);
build(i << 1 | 1, M, R);
} void pushDown(int i)
{
if (N[i].r-N[i].l<=1) return;
if (N[i].cov!=0){
N[i << 1].cov += N[i].cov;
N[i << 1 | 1].cov += N[i].cov;
N[i].cov = 0;
}
} void add(int i, int L, int R,int val)
{
if (N[i].l == L&&N[i].r == R){
N[i].cov += val;
return;
}
pushDown(i);
int M = (N[i].l + N[i].r) >> 1;
if (R <= M) add(i << 1, L, R, val);
else if (L >= M) add(i << 1 | 1, L, R, val);
else {
add(i << 1, L, M, val);
add(i << 1 | 1, M, R, val);
}
} double query(int i)
{
pushDown(i);
if (N[i].r - N[i].l <= 1&&N[i].cov>0) return N[i].len;
else if (N[i].r - N[i].l <= 1) return 0;
return query(i << 1) + query(i << 1 | 1);
} int main()
{
int ca = 0;
while (cin >> n&&n)
{
double x1, y1, x2, y2; top = 0; ytop = 0;
for (int i = 0; i < n; i++){
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
s[top].x = x1; s[top].l = y1; s[top].r = y2; s[top++].isleft = true;
s[top].x = x2; s[top].l = y1; s[top].r = y2; s[top++].isleft = false;
ydis[ytop++] = y1; ydis[ytop++] = y2;
}
sort(ydis, ydis + ytop);
ytop = unique(ydis, ydis + ytop) - ydis;
sort(s, s + top);
for (int i = 0; i < top; i++){
s[i].li = lower_bound(ydis, ydis + ytop, s[i].l) - ydis;
s[i].ri = lower_bound(ydis, ydis + ytop, s[i].r) - ydis;
}
ydis[ytop] = ydis[ytop - 1];
build(1, 0, ytop); double ans = 0;double lx = s[0].x;
for (int i = 0; i < top; i++){
ans += query(1)*(s[i].x - lx);
if (s[i].isleft){
add(1, s[i].li, s[i].ri ,1);
}
else{
add(1, s[i].li, s[i].ri, -1);
}
lx = s[i].x;
}
printf("Test case #%d\n", ++ca);
printf("Total explored area: %.2lf\n", ans);
puts("");
}
return 0;
}
HDU1542 Atlantis(矩形面积并)的更多相关文章
- hdu1542 Atlantis(矩阵面积的并)
这个题算是我的第一个扫描线的题,扫描线算是一种思想吧,用到线段树+离散化.感觉高大上. 主要参考了这位大神的博客. http://www.cnblogs.com/kuangbin/archive/20 ...
- 【HDU 1542】Atlantis 矩形面积并(线段树,扫描法)
[题目] Atlantis Problem Description There are several ancient Greek texts that contain descriptions of ...
- HDU1542 扫描线(矩形面积并)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- (HDU 1542) Atlantis 矩形面积并——扫描线
n个矩形,可以重叠,求面积并. n<=100: 暴力模拟扫描线.模拟赛大水题.(n^2) 甚至网上一种“分块”:分成n^2块,每一块看是否属于一个矩形. 甚至这个题就可以这么做. n<=1 ...
- POJ 1151 Atlantis 矩形面积求交/线段树扫描线
Atlantis 题目连接 http://poj.org/problem?id=1151 Description here are several ancient Greek texts that c ...
- POJ-1151 Atlantis 矩形面积并
题目链接:http://poj.org/problem?id=1151 扫描线+离散+线段树,线段树每个节点保存的是离散后节点右边的线段. //STATUS:C++_AC_16MS_208KB #in ...
- poj1151 Atlantis && cdoj 1600艾尔大停电 矩形面积并
题目: Atlantis Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23758 Accepted: 8834 Des ...
- hdu 1542&&poj 1151 Atlantis[线段树+扫描线求矩形面积的并]
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU 1542"Atlantis"(线段树+扫描线求矩形面积并)
传送门 •题意 给你 n 矩形,每个矩形给出你 $(x_1,y_1),(x_2,y_2)$ 分别表示这个矩形的左下角和右上角坐标: 让你求这 n 个矩形并的面积: 其中 $x \leq 10^{5} ...
随机推荐
- rails的字符编码
想练练手,随意的写了个登陆页面,简单的只有几行. <%= form_tag('login_check') do -%><%= text_field_tag 'user_name', ...
- unix的策略与机制
策略同机制分离,接口同引擎分离 Linux/Unix设计理念提供的一种机制不是策略.如果说机制是一种框架,那么,策略就是填充框架的一个个具体实施.机制提供的就是一种开放而宽松的环境,而策略就是在这个环 ...
- zeromq
分布式系统之分布式中间件zeroMQ zeroMQ,又称0MQ,是一个非常简单的通信库,它扩展了传统BSD socket能力,提供简单的基于消息的通信.zeroMQ不解析消息体,没有序列化能力,或者说 ...
- 自学asp.net mvc(三)
1.将前台框架的登录页面代码,复制到Login.cshtml. 2.将文本框替换. 3.缓存机制. 4.类图
- 4.FPGA芯片管脚解释
用户I/O:不用解释了. 配置管脚: MSEL[1:0] 用于选择配置模式,比如AS.PS等. DATA0 FPGA串行数据输入,连接到配置器件的串行数据输出管脚. DCLK FPGA串行时钟输出 ...
- 【BZOJ 2324】 [ZJOI2011]营救皮卡丘
Description 皮卡丘被火箭队用邪恶的计谋抢走了!这三个坏家伙还给小智留下了赤果果的挑衅!为了皮卡丘,也为了正义,小智和他的朋友们义不容辞的踏上了营救皮卡丘的道路. 火箭队一共有N个据点,据点 ...
- 盘点Windows 8.1中隐藏着的25个秘密功能
Windows 8.1正式版问世,带来了众多大家早已耳熟能详的“开始按钮”.“分屏显示”等功能.事实上,Windows 8.1贴心的设计细节有很多,多数细节隐藏于系统中某个不起眼的角落,科技网站PC ...
- M1事后分析报告(Postmortem Report)
M1事后分析报告(Postmortem Report) 设想和目标 1. 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? 我们项目组所开发的软件为一个基于Andro ...
- 随堂作业——到底有几个“1”(C++)
一.设计思路 在课堂上讨论的时候,老师提出的思路是利用之前的结果计算出比它更大的数字的“1”.但是我不是这么想的,我是把输入的正整数每位上的数都分解出来计算.如abc,就先算c,再加上b,最后再加上a ...
- Facebook Graph API 接口请求
Graph API 调试器 这两天因项目需求,在调试FB的接口.项目的应用在FB上面.L特傻.没有区分FB的api的使用方式. 因为应用是在FB上面的.所以在登录应用的时候,就已经登录了FB平台.对于 ...