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出一条直线从左到右(也可以从上到下)扫描过去,此时先将所 ...
随机推荐
- [ Continuously Update ] The Paper List of Image / Video Captioning
Papers Published in 2018 Convolutional Image Captioning - Jyoti Aneja et al., CVPR 2018 - [ Paper Re ...
- WCF:REST + Basic authentification + IIS
近期一个项目中用到Restful WCF提供服务,但是需要验证机制,网上搜刮了一些,都是太复杂.FQ找到了一篇不错的文章分享一下. 原地址连接:http://vgolovchenko.wordpres ...
- .net转PHP从零开始-环境的搭建
PHP初级开发环境安装很简单,只需要使用一键安装的phpstudy 下载地址:http://www.phpstudy.net/ 安装后可以看到 这样的界面,设置好相关的配置,然后,选择查看phpinf ...
- [leetcode-670-Maximum Swap]
Given a non-negative integer, you could swap two digits at most once to get the maximum valued numbe ...
- Thunder团队第六周 - Scrum会议3
Scrum会议3 小组名称:Thunder 项目名称:i阅app Scrum Master:李传康 工作照片: 参会成员: 王航:http://www.cnblogs.com/wangh013/ 李传 ...
- Generating a PDF in Codeigniter using mPDF
https://arjunphp.com/generating-a-pdf-in-codeigniter-using-mpdf/
- <Effective C++>读书摘要--Inheritance and Object-Oriented Design<二>
<Item 36> Never redefine an inherited non-virtual function 1.如下代码通过不同指针调用同一个对象的同一个函数会产生不同的行为Th ...
- 【转】bind简单示例
bind简单示例代码 namespace { class placeholder_ {}; placeholder_ __1; } template <typename R, typename ...
- vim 删除文件全部内容
很多时候我们需要删除脚本文件全部内容, 重新再写入新的内容,进行其他的操作: 很多时候我们对应用程序的排错需要查看日志文件,然而日志中通常有许多我们以前的应用程序产生的日志,其他的日志过多的时候,有时 ...
- C#的垃圾回收
C#中垃圾回收 GC.Collect();强制进行内存回收.