hdu 1542 Atlantis 段树区,并寻求,,,尼玛真坑人数据,不要打开一小阵!
Atlantis
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7815 Accepted Submission(s): 3420
friend Bill has to know the total area for which maps exist. You (unwisely) volunteered to write a program that calculates this quantity.
(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.
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.
2
10 10 20 20
15 15 25 25.5
0
Test case #1
Total explored area: 180.00
#include <cstdio>
#include <algorithm> using namespace std ; double y[300] ; struct Line{
double x , y_up , y_down ;
int mark ;
}line[300] ; //開始开到110,WA另外三次。! 后来看discuss改后就A了! struct Node{
double x ,y_up,y_down ;
int cover ;
bool isLeaf ;
}st[400100]; bool cmp(const Line &a , const Line &b)
{
return a.x<b.x ;
} void build(int l ,int r , int pos)
{
st[pos].cover = 0 ;
st[pos].y_down = y[l] ;
st[pos].y_up = y[r] ;
st[pos].x = -1 ;
st[pos].isLeaf = false ;
if(l+1 == r)
{
st[pos].isLeaf = true ;
return ;
}
int mid = (l+r)>>1 ;
build(l,mid,pos<<1);
build(mid,r,pos<<1|1) ;
} double insert(double x , double y_up , double y_down , int mark , int pos)
{
if(st[pos].y_down>=y_up || st[pos].y_up<=y_down)
{
return 0 ;
}
if(st[pos].isLeaf)
{
if(st[pos].cover>0)
{
double temp = st[pos].x ;
double area = (x-temp)*(st[pos].y_up-st[pos].y_down) ;
st[pos].x = x ;
st[pos].cover += mark ;
return area ;
}
else
{
st[pos].x = x ;
st[pos].cover += mark ;
return 0 ;
}
}
return insert(x,y_up,y_down,mark,pos<<1)+insert(x,y_up,y_down,mark,pos<<1|1) ;
} int main()
{
int n , c = 1;
while(~scanf("%d",&n) && n)
{
int index = 0 ;
for(int i = 0 ; i < n ; ++i)
{
double x1,y1,x2,y2 ;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2) ;
line[index].x = x1 ;
line[index].y_down = y1 ;
line[index].y_up = y2 ;
y[index] = y1 ;
line[index++].mark = 1 ; line[index].x = x2 ;
line[index].y_down = y1 ;
line[index].y_up = y2 ;
y[index] = y2 ;
line[index++].mark = -1 ;
}
sort(y,y+index) ;
sort(line,line+index,cmp) ;
build(0,index-1,1) ;
double area = 0.0 ;
for(int i = 0 ; i < index ; ++i)
{
area += insert(line[i].x,line[i].y_up,line[i].y_down,line[i].mark,1) ;
}
printf("Test case #%d\n",c++) ;
printf("Total explored area: %.2lf\n\n",area) ;
}
return 0 ;
}
而共勉之王
hdu 1542 Atlantis 段树区,并寻求,,,尼玛真坑人数据,不要打开一小阵!的更多相关文章
- hdu 1542 Atlantis(段树&扫描线&面积和)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU 1542 - Atlantis - [线段树+扫描线]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- HDU 1542.Atlantis-线段树求矩形面积并(离散化、扫描线/线段树)-贴模板
好久没写过博客了,这学期不是很有热情去写博客,写过的题也懒得写题解.现在来水一水博客,写一下若干年前的题目的题解. Atlantis Time Limit: 2000/1000 MS (Java/Ot ...
- hdu 1542 Atlantis(线段树,扫描线)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- HDU 1542 Atlantis(线段树面积并)
描述 There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. S ...
- HDU 1542 Atlantis (线段树 + 扫描线 + 离散化)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- POJ 1151 / HDU 1542 Atlantis 线段树求矩形面积并
题意:给出矩形两对角点坐标,求矩形面积并. 解法:线段树+离散化. 每加入一个矩形,将两个y值加入yy数组以待离散化,将左边界cover值置为1,右边界置为2,离散后建立的线段树其实是以y值建的树,线 ...
- hdu 1542 Atlantis (线段树扫描线)
大意: 求矩形面积并. 枚举$x$坐标, 线段树维护$[y_1,y_2]$内的边是否被覆盖, 线段树维护边时需要将每条边挂在左端点上. #include <iostream> #inclu ...
- (HDU 1542) Atlantis 矩形面积并——扫描线
n个矩形,可以重叠,求面积并. n<=100: 暴力模拟扫描线.模拟赛大水题.(n^2) 甚至网上一种“分块”:分成n^2块,每一块看是否属于一个矩形. 甚至这个题就可以这么做. n<=1 ...
随机推荐
- trie + 长度优先匹配,生成串
import com.google.common.collect.Maps; import java.util.Map; /** * tree 节点 * Created by shuly on 16- ...
- 使用CMakeLists.txt 判断编译器是否支持C++11
#将下面的内容添加到CMakeLists.txt当中include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++11&quo ...
- linux 手动安装 oracle(转)
Linux下安装Oracle 11 此为参照CU论坛上的高人写的文章并结合自身环境增加了点细节性的东西 操作系统 CentOS 4.2 2.6.11.8内核 安装准备 下载Oracle11安装包 内存 ...
- 经excel要将数据库(ORACLE)要插入数据
大家都知道PL/SQL可以excel数据复制.我们也可以通过相同excel将数据插入到数据库. 下面我们就来简单的样品,并与主题演示 首先,我们创建了一个表test CREATE TABLE test ...
- uva10341 - solve it (二分查找)
题目:uva10341-solve it 题目大意:求解给定的方程式解题思路:由于这个方程式在给定的x的范围内是单调递减的.所以能够用二分查找来尝试x的值.这里的 x是要求保留4小数,所以当区间缩小到 ...
- Android访问服务器(TOMCAT)乱码引发的问题
1.浏览器往服务器发送的请求主要可分为2种:get.post:delete.head等不赘述. GET方式: 从浏览器上直接敲地址,最大特点就是参数直接跟在地址后面. POST方式:表单提交等. 2. ...
- SNMP WINDOWS系统的命令行工具下载
SNMP windows系统的命令行工具snmputil.exe下载链接:请点击
- Android - 和其他APP交互 - 获得activity的返回值
启用另一个activity不一定是单向的.也可以启用另一个activity并且获得返回值.要获得返回值的话,调用startActivityForResult()(而不是startActivity()) ...
- [Android 4.4.4] 泛泰A870 通过刷第三版 Mokee4.4.4 KTU84P 20140626 RC2.1 by syhost
主题及注意事项请访问以前的版本: http://blog.csdn.net/syhost/article/details/29931291 此RC2.1版比RC2.0改进的地方: 1. Mokee本身 ...
- 纯洁CSS实现下拉菜单和下拉容器(纯洁CSS导航栏和导航下拉容器)
虽然网上课程似即使案件大同小异,但我还是写,记笔记,也为您提供参考 我希望你能指导批评~~ 首先,我们必须列出ul li 开始我们的导航栏菜单也能说生产: 在下面的页面,我们先建XHTML结构体: & ...