HDU 1255 覆盖的面积 ( 扫描线 + 离散 求矩阵大于k次面积并 )
覆盖的面积
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4040 Accepted Submission(s): 1995

入数据的第一行是一个正整数T(1<=T<=100),代表测试数据的数量.每个测试数据的第一行是一个正整数N(1<=N&
lt;=1000),代表矩形的数量,然后是N行数据,每一行包含四个浮点数,代表平面上的一个矩形的左上角坐标和右下角坐标,矩形的上下边和X轴平行,
左右边和Y轴平行.坐标的范围从0到100000.
注意:本题的输入数据较多,推荐使用scanf读入数据.
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
using namespace std;
#define root 1,(n<<1)+10,1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define lr rt<<1
#define rr rt<<1|1 const int N = ; struct Point {
double x , y1 , y2 ;
int v ;
bool operator < ( const Point &a ) const {
return x < a.x ;
}
}p[N];
int n , tot , tt ;
vector<double>e;
double c[N<<] ; void addpoint( double x , double y1 , double y2 , int v ) {
p[tot].x = x , p[tot].y1 = y1 , p[tot].y2 = y2 , p[tot].v = v , tot++ ;
}
map<double,int>mp; void lisan() {
mp.clear();
sort( e.begin() , e.end() ) ;
tt = ;
for( int i = ; i < e.size() ; ++i ) {
if( e[i] != e[i-] ) e[tt++] = e[i] ;
}
for( int i = ; i < tt ; ++i ) {
c[i+] = e[i] ;
mp[e[i]] = i+ ;
}
} int cnt[N<<] , lazy[N<<] ; double date[N<<] ; void build( int l , int r , int rt ) {
cnt[rt] = lazy[rt] = ;
if( l == r ) {
date[rt] = c[l+] - c[l];
return ;
}
int mid = (l+r)>>;
build(lson) , build(rson) ;
date[rt] = date[lr] + date[rr];
} void Down( int rt ) {
if( lazy[rt] ) {
cnt[lr] += lazy[rt] ;
cnt[rr] += lazy[rt] ;
lazy[lr] += lazy[rt] ;
lazy[rr] += lazy[rt] ;
lazy[rt] = ;
}
} void Up( int rt ) {
cnt[rt] = min( cnt[lr] , cnt[rr] );
} void update( int l , int r , int rt , int L , int R , int v ) {
if( l == L && r == R ) {
cnt[rt] += v ; lazy[rt] += v ;
return ;
}
int mid = (l+r)>> ;
Down(rt) ;
if( R <= mid ) update(lson,L,R,v) ;
else if( L > mid ) update( rson,L,R,v);
else update(lson,L,mid,v),update(rson,mid+,R,v);
Up(rt);
} double query( int l , int r , int rt , int L , int R ) {
if( cnt[rt] > ) return date[rt] ;
if( l == r ) return ;
Down(rt);
int mid = (l+r)>>;
if( R <= mid ) return query(lson,L,R);
else if( L > mid ) return query(rson,L,R);
else return query(lson,L,mid) + query(rson,mid+,R);
} int main() {
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
int _ ; scanf("%d",&_);
while( _-- ) {
scanf("%d",&n);
e.clear();
tot = ;
for( int i = ; i < n ; ++i ) {
double x1 , y1 , x2 , y2 ;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
if( y1 > y2 ) swap( y1 , y2 ) ;
addpoint( x1 , y1 , y2 , );
addpoint( x2 , y1 , y2 , - );
e.push_back(y1);
e.push_back(y2);
}
lisan();
sort( p , p + tot ) ;
build(,tt-,);
double ans = ;
update(,tt-,,mp[p[].y1],mp[p[].y2]-,p[].v);
for( int i = ; i < tot ; ++i ) {
ans += ( p[i].x - p[i-].x ) * query(,tt-,,,tt-) ;
update(,tt-,,mp[p[i].y1],mp[p[i].y2]-,p[i].v);
}
printf("%.2lf\n",ans);
}
return ;
}
HDU 1255 覆盖的面积 ( 扫描线 + 离散 求矩阵大于k次面积并 )的更多相关文章
- FZU 2187 回家种地 ( 扫描线 + 离散 求矩阵单次覆盖面积 )
2187 回家种地 Accept: 56 Submit: 230Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Descript ...
- HDU 4417 Super Mario(划分树问题求不大于k的数有多少)
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU - 1255 覆盖的面积(线段树求矩形面积交 扫描线+离散化)
链接:线段树求矩形面积并 扫描线+离散化 1.给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. 2.看完线段树求矩形面积并 的方法后,再看这题,求的是矩形面积交,类同. 求面积时,用被覆 ...
- hdu 1255 覆盖的面积(求覆盖至少两次以上的面积)
了校赛,还有什么途径可以申请加入ACM校队? 覆盖的面积 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- hdu 1255 覆盖的面积(线段树 面积 交) (待整理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 Description 给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. In ...
- HDU 1255 覆盖的面积 (线段树扫描线+面积交)
自己YY了一个的写法,不过时间复杂度太高了,网上的想法太6了 题意:给你一些矩阵,求出矩阵的面积并 首先按照x轴离散化线段到线段树上(因为是找连续区间,所以段建树更加好做). 然后我们可以想一下怎样 ...
- HDU 1255 覆盖的面积(线段树+扫描线)
题目地址:HDU 1255 这题跟面积并的方法非常像,仅仅只是须要再加一个变量. 刚開始我以为直接用那个变量即可,仅仅只是推断是否大于0改成推断是否大于1.可是后来发现了个问题,由于这个没有下放,没延 ...
- HDU 1255 覆盖的面积 (线段树+扫描线+离散化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1255 题意很清楚,就是让你求矩阵之间叠加层数大于1的矩形块的面积和. 因为n只有1000,所以我离散化 ...
- hdu 1255 覆盖的面积 (线段树处理面积覆盖问题(模板))
http://acm.hdu.edu.cn/showproblem.php?pid=1255 覆盖的面积 Time Limit: 10000/5000 MS (Java/Others) Memo ...
随机推荐
- 一、Rabbit使用-安装教程
首先我去官网上面下载RabbitMQ安装包:https://www.rabbitmq.com/which-erlang.html 现在下载的版本是3.7.17 因为我erlong安装的是20.3
- 我是如何用python给Thunar写GUI插件的 (pygtk+glade)
更新:zip乱码的问题可以通过安装patch之后的p7zip-natspec和unzip-natspec解决(archlinuxcn源),而仍使用Engrampa做前端.此文重点在pygtk... 问 ...
- python基础--内置函数map
num_1=[1,2,10,5,3,7] # num_2=[] # for i in num_1: # num_2.append(i**2) # print(num_2) # def map_test ...
- 【LeetCode】二叉查找树 binary search tree(共14题)
链接:https://leetcode.com/tag/binary-search-tree/ [220]Contains Duplicate III (2019年4月20日) (好题) Given ...
- web编程jsp小tips
jsp文件头 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEn ...
- layer-框架使用修改部分
关于框架中js调子方法出错的处理 top.layer.open({ id: options.id, type: 2, shade: options.shade, title: options.titl ...
- pycharm安装第三方库失败module 'pip' has no attribute 'main'
用的pycharm2017.3,新创建一个项目,在安装appium-python-client时报错module 'pip' has no attribute 'main'.通过强大的度娘,知道是pi ...
- http各个状态码的含义
http各个状态码的含义:由三位数字组成,第一位定义了状态码的类型 常见状态码及解决方法 404:找不到,地址错误 500:逻辑错误 400:一般是入参不匹配 504:超时 2开头:(请求成功)表示成 ...
- @ResponseBody和@RestController
Spring 关于ResponseBody注解的作用 responseBody一般是作用在方法上的,加上该注解表示该方法的返回结果直接写到Http response Body中,常用在ajax异步请求 ...
- DELPHI FMX 同时使用LONGTAP和TAP
在应用到管理图标时,如长按显示删除标志,单击取消删除标志.在FMX的手势管理中,只有长按LONGTAP,点击TAP则是单独的事件,不能在同事件中管理.在执行LONGTAP后,TAP也会被触发,解决方 ...