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 ...
 
随机推荐
- 三白话经典算法系列 Shell排序实现
			
山是包插入的精髓排序排序,这种方法,也被称为窄增量排序.因为DL.Shell至1959提出命名. 该方法的基本思想是:先将整个待排元素序列切割成若干个子序列(由相隔某个"增量"的元 ...
 - 安卓的sqlite增删改
			
基于安卓的sqlite增删改,笔记学习: 1.使用LinearLayout 布局生成,增删改的页面如图 代码布局如下: <LinearLayout xmlns:android="htt ...
 - HTML5_表单元素
			
<!DOCTYPE html> <hmtl> <html lang="zh-cn"> <head> <meta charse ...
 - [BEROR]CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 8.1'
			
解决方法: 选择project->Build Settings -> Code Signing -> Code Signing Identity -> Debug -> ...
 - 20那天android得知
			
20多天的实习(事实上,一个人学习的东西)要结束, 剩下的只是读研. 这项20许多天我学到了很多东西, 对android的发展也有了一定的了解.之后写这篇文章主要完成的研究可以得知快速回升 1.安德鲁 ...
 - Linux中查看socket状态(转)
			
Linux中查看socket状态:cat /proc/net/sockstat #(这个是ipv4的) sockets: used 137 TCP: inuse 49 orphan 0 tw 3272 ...
 - MySQL replace 的简介
			
今天同学discuz升级出现主键反复,导致数据插入不成功的问题,然后查找了一下,说的方法都是用replace into替换insert into,然后对replace into进行了查询,以下做一下简 ...
 - 怎样配置git ssh连接,怎样在GitHub上加入协作开发人员,怎样配置gitignore和怎样在GitHub上删除资源库.
			
**********1.在运行git push origin master指令时报例如以下错误: iluckysi@ILUCKYSI-PC /d/ilucky/message/code (master ...
 - ASP.NET之AdRotator实现淘宝浏览页面的商品随机推荐功能
			
如今随便上个网都能够看到淘宝.京东等各大电商平台的双十一购物狂欢宣传,从2009年開始淘宝愣是把11.11这一天打造成了全民购物狂欢节.阿里巴巴的上市更是激发了阿里人的斗志,据说他们今年的目标是100 ...
 - 声明式编程思想和EEPlat
			
声明式编程定义 声明式编程(英语:Declarativeprogramming)它是一种编程范式.程相对立.它描写叙述目目标性质,让计算机明白目标,而非流程. 声明式编程不用告诉电脑问题领域.从而避免 ...