CodeForces 610D Vika and Segments
模板题,矩形面积并
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define maxn 220000
#define lson l,m,rt << 1
#define rson m + 1,r,rt << 1 | 1
#define eps 1e-15
using namespace std;
struct seg
{
double l,r,y;
int sign;
seg() {}
seg(double a, double b, double h, int s): l(a), r(b),y(h),sign(s) {}
bool operator < (const seg &cmp) const
{
if(cmp.y == y) return sign > cmp.sign;
return y < cmp.y;
}
} p[ (maxn << )+ ]; double sum[ (maxn << )+ ];
int cnt[ (maxn << ) + ]; double X[ (maxn << ) + ]; void push_up(int rt,int l, int r)
{
if(cnt[rt]) sum[rt] = X[r + ] - X[l]; else if(l == r) sum[rt] = 0.0; else sum[rt] = sum[rt << ] + sum[rt << | ];
}
void update(int L, int R, int cc, int l , int r, int rt)
{
if(L <= l && r <= R)
{
cnt[rt] += cc;
push_up(rt,l,r);
return ;
}
int m = (l + r) >> ;
if(L <= m) update(L,R,cc,lson);
if(R > m) update(L,R,cc,rson);
push_up(rt,l,r);
}
int bin(int low, int high, double key)
{
int mid ;
while(low < high)
{
mid = (low + high) >> ;
if(X[mid] < key ) low = mid + ;
else high = mid;
}
return low;
}
int main()
{
int n,m,k,pp,ca = ;
double a,b,c,d,ret;
while(scanf("%d",&n) != EOF && n)
{
memset(sum,,sizeof(sum));
memset(cnt,,sizeof(cnt));
m = k = ;
ret = 0.0;
pp = ; for(int i = ; i < n; i ++)
{
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
if(b==d)
{
if(a>c) swap(a,c);
}
else if(a==c)
{
if(b>d) swap(b,d);
}
c++;
d++;
X[m ++] = a;
X[m ++] = c; p[k ++] = seg(a,c,b,); p[k ++] = seg(a,c,d,-);
}
sort(X,X + m);
sort(p,p + k); for(int i = ; i < m; i ++)
if(X[i - ] != X[i])
{
X[pp ++] = X[i];
} pp --;
for(int i = ; i < k - ; i ++)
{
int l = bin(, pp , p[i].l);
int r = bin(, pp , p[i].r) - ;
if(l <= r) update(l,r,p[i].sign,,pp,);
ret += (p[i + ].y - p[i].y) * sum[];
}
printf("%.0f\n",ret);
}
return ;
}
CodeForces 610D Vika and Segments的更多相关文章
- Codeforces 610D Vika and Segments 线段树+离散化+扫描线
可以转变成上一题(hdu1542)的形式,把每条线段变成宽为1的矩形,求矩形面积并 要注意的就是转化为右下角的点需要x+1,y-1,画一条线就能看出来了 #include<bits/stdc++ ...
- 610D - Vika and Segments(线段树+扫描线+离散化)
扫描线:http://www.cnblogs.com/scau20110726/archive/2013/04/12/3016765.html 看图,图中的数字是横坐标离散后对应的下标,计算时左端点不 ...
- codeforces 610D D. Vika and Segments(离散化+线段树+扫描线算法)
题目链接: D. Vika and Segments time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树扫描线
D. Vika and Segments 题目连接: http://www.codeforces.com/contest/610/problem/D Description Vika has an i ...
- Codeforces Round #337 (Div. 2) D. Vika and Segments 线段树 矩阵面积并
D. Vika and Segments Vika has an infinite sheet of squared paper. Initially all squares are whit ...
- Codeforces Round #337 Vika and Segments
D. Vika and Segments time limit per test: 2 seconds memory limit per test: 256 megabytes input ...
- 【20.51%】【codeforces 610D】Vika and Segments
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Codeforces Round #337 (Div. 2) D. Vika and Segments (线段树+扫描线+离散化)
题目链接:http://codeforces.com/contest/610/problem/D 就是给你宽度为1的n个线段,然你求总共有多少单位的长度. 相当于用线段树求面积并,只不过宽为1,注意y ...
- Vika and Segments - CF610D
Vika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-d ...
随机推荐
- json解析尖括号<>
如题 rs.getString("HEADLINE").replaceAll("<", " <").replaceAll(&qu ...
- wpa_supplicant_8_ti hostapd wpa_supplicant TI 官方的wpa_supplicant hostapd 移植到linux
在移植 wpa_supplicant_8_ti 的时候碰到很多头文件找不到.然后参考了下面的博客 http://blog.csdn.net/penglijiang/article/details/85 ...
- Python 模块功能paramiko SSH 远程执行及远程下载
模块 paramiko paramiko是一个用于做远程控制的模块,使用该模块可以对远程服务器进行命令或文件操作,值得一说的是,fabric和ansible内部的远程管理就是使用的paramiko来现 ...
- max_%_connection参数详解
对于连接数的设置,show variables里有三个参数可以对它进行控制,max_connections与max_user_connections以及max_connect_errors.下面对这三 ...
- eclipse无法导入已有android项目
问题: 今天发现我拷贝的一个android项目无法导入到eclipse,但是其它的已有android项目却可以导入 思路 现在网络这么流行,当然是上网查,得益于eclipse无法导入Android工程 ...
- zzuli 1919 数列划分
题面: Description 晴天想把一个包含n个整数的序列a分成连续的若干段,且和最大的一段的值最小,但他有强迫症,分的段数不能超过m段,然后他就不会分了...他想问你这个分出来的和最大的一段的和 ...
- GameUnity 2.0 文档(三) 纸片人八方向
DirectSprite类 有别于 上篇文档出现的 AnimationSprite类 (从头播放到尾) 这个类根据 path的图,如果是 8*8 64个图 八方向,可以设置长宽和 角度 角度 代表 8 ...
- IE6下绝对定位元素和浮动元素并列绝对定位元素消失
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- hdu_5691_Sitting in Line(状压DP)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5691 题意:中文,不解释 题解:设dp[i][j]表示当前状态为i,以第j个数为末尾的最忧解,然后dp ...
- PHP使用Redis
首先确保安装了Redis扩展 详细的使用方式 请浏览扩展文档 https://github.com/phpredis/phpredis#connection $obj = new Redis(); $ ...