Atlantis HDU - 1542 (线段树扫描线)
InputThe 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.OutputFor 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 这题也是模板提
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
using namespace std;
#define bug printf("******\n");
#define rtl rt<<1
#define rtr rt<<1|1
typedef long long LL;
const int maxn = 1e5 + ;
struct LINE {
double x, y1, y2;
int flag;
} line[];
int cmp(LINE a, LINE b) {
return a.x < b.x;
}
struct node {
double pre, l, r;
int cover, flag;
} tree[];
double y[];
void build(int rt, int l, int r) {
tree[rt].l = y[l], tree[rt].r = y[r];
tree[rt].flag = -, tree[rt].cover = , tree[rt].pre = -;
if (l + == r) {
tree[rt].flag = ;
return ;
}
int m = (l + r) >> ;
build(rtl, l, m);
build(rtr, m, r);
}
double query(int rt, double x, double y1, double y2, int flag) {
if (tree[rt].r <= y1 || tree[rt].l >= y2) return ;
if (tree[rt].flag == ) {
if (tree[rt].cover > ) {
double pre = tree[rt].pre;
double ans = (x - pre) * (tree[rt].r - tree[rt].l);
tree[rt].pre = x;
tree[rt].cover += flag;
return ans;
} else {
tree[rt].cover += flag;
tree[rt].pre = x;
return ;
}
}
return query(rtl, x, y1, y2, flag) + query(rtr, x, y1, y2, flag);
}
int main() {
int cas = , n;
while(scanf("%d", &n), n) {
int cnt = -;
for (int i = ; i < n ; i++) {
double x1, y1, x2, y2;
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
y[++cnt] = y1;
line[cnt].flag = ;
line[cnt].x = x1;
line[cnt].y1 = y1;
line[cnt].y2 = y2;
y[++cnt] = y2;
line[cnt].flag = -;
line[cnt].x = x2;
line[cnt].y1 = y1;
line[cnt].y2 = y2;
}
sort(y, y + cnt + );
sort(line, line + cnt + , cmp);
build(, , cnt);
double ans = ;
for (int i = ; i <= cnt ; i++ )
ans += query(, line[i].x, line[i].y1, line[i].y2, line[i].flag);
printf("Test case #%d\n", cas++);
printf("Total explored area: %.2lf\n\n", ans);
}
return ;
}
Atlantis HDU - 1542 (线段树扫描线)的更多相关文章
- Atlantis HDU - 1542 线段树+扫描线 求交叉图形面积
//永远只考虑根节点的信息,说明在query时不会调用pushdown //所有操作均是成对出现,且先加后减 // #include <cstdio> #include <cstri ...
- hdu 1542 线段树+扫描线 学习
学习扫描线ing... 玄学的东西... 扫描线其实就是用一条假想的线去扫描一堆矩形,借以求出他们的面积或周长(这一篇是面积,下一篇是周长) 扫描线求面积的主要思想就是对一个二维的矩形的某一维上建立一 ...
- HDU 1542 线段树+扫描线+离散化
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- hdu 1542 线段树扫描(面积)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- hdu 4052 线段树扫描线、奇特处理
Adding New Machine Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 1828 线段树扫描线(周长)
Picture Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- hdu 5091(线段树+扫描线)
上海邀请赛的一道题目,看比赛时很多队伍水过去了,当时还想了好久却没有发现这题有什么水题的性质,原来是道成题. 最近学习了下线段树扫描线才发现确实是挺水的一道题. hdu5091 #include &l ...
- HDU 5107 线段树扫描线
给出N个点(x,y).每一个点有一个高度h 给出M次询问.问在(x,y)范围内第k小的高度是多少,没有输出-1 (k<=10) 线段树扫描线 首先离散化Y坐标,以Y坐标建立线段树 对全部的点和询 ...
- hdu 1542 线段树之扫描线之面积并
点击打开链接 题意:给你n个矩形,求它们的面积,反复的不反复计算 思路:用线段树的扫描线完毕.将X坐标离散化后,从下到上扫描矩形,进行各种处理,看代码凝视把 #include <stdio.h& ...
- hdu 1255(线段树 扫描线) 覆盖的面积
http://acm.hdu.edu.cn/showproblem.php?pid=1255 典型线段树辅助扫描线,顾名思义扫描线就是相当于yy出一条直线从左到右(也可以从上到下)扫描过去,此时先将所 ...
随机推荐
- JS的六大对象:Global、Math、Number、Date、JSON、console,运行在服务器上方的支持情况分析
在ASP中使用runat="server"来调用JS的相关函数,代码如下: <script runat="server" language="j ...
- TW实习日记:第14天
今天可以说是又忙又不忙了,忙是因为要赶bug,似乎总有种隐形的力量催着你交工,但实际上太多涉及后端接口的问题,所以又要等别人修改接口才能改bug,可以说真是十分蛋疼了. 改bug的最大心得就是:写好注 ...
- CsvHelper文档-2读
CsvHelper文档-2读 这个库默认不需要做任何设置就可以很容易的使用它.如果你的类属性名称直接匹配csv的标题名称,那么可以按照下面的实例来用: (以下所有的代码都需要引用using csvhe ...
- 火狐metamask账号
火狐metamask lock trophy pyramid sunny aim inmate body sense sing castle cinnamon cram
- HDU 4302 Holedox Eating (线段树模拟)
题意:一个老鼠在一条长度为L的直线上跑,吃蛋糕,老鼠只能沿直线移动.开始时没有蛋糕,老鼠的初始位置是0. 有两个操作,0 x 代表在位置x添加一个蛋糕: 1 代表老鼠想吃蛋糕.老鼠每次都会选择离自己最 ...
- Git 命令详解及常用命令
Git 命令详解及常用命令 Git作为常用的版本控制工具,多了解一些命令,将能省去很多时间,下面这张图是比较好的一张,贴出了看一下: 关于git,首先需要了解几个名词,如下: 1 2 3 4 Work ...
- Python中的名字隐藏
Python对于module文件中的name是没有private和public区分的,严格来说,在module文件重定义的任何name,都可以被外界访问.但是,对于 from module imort ...
- Python中from module import *语法
from module import *的语法在Python 3.X和Python 2.X中的使用稍有区别: 在Python 3.X中,from module import *无法在函数里面使用,而在 ...
- DAY5敏捷冲刺
站立式会议 工作安排 (1)服务器配置 对单词学习的记录储存 (2)数据库配置 单词学习记录+用户信息 燃尽图 燃尽图有误,已重新修改,先贴卡片的界面,后面补修改后燃尽图 代码提交记录
- 在用js拼接html时,给元素加不上事件的问题
问题描述:有时,发起ajax请求成功后,需要用js去拼接一小段html字符串,然后给某些元素添加事件时,事件总是加不上. 解决办法:在success 回调函数内,给元素添加事件绑定. 代码如下: $. ...