【bzoj5183】[Baltic2016]Park 离线+对偶图+并查集
题目描述
输入
输出
样例输入
5 3
16 11
11 8 1
6 10 1
7 3 2
10 4 1
15 5 1
1 1
2 2
2 1
样例输出
1234
2
14
题解
离线+对偶图+并查集
套路:如果两棵树或树与边界之间无法通过,则视作它们之间连了一条边。
那么左下角能到右下角等价于:下边界与左、上、右边界都不连通。其余同理。
然而每个人的半径都不同,对每个人单独处理必T无疑。考虑离线,将人按照半径、树与树和树与边界按照能通过的最大距离从小到大排序然后处理即可。
连通性可以直接使用并查集维护。
时间复杂度 $O(n^2\log n+m\log m+m\times 常数)$
#include <cmath>
#include <cstdio>
#include <algorithm>
#define squ(x) (x) * (x)
using namespace std;
struct data
{
double d;
int x , y;
data() {}
data(double a , int b , int c) {d = a , x = b , y = c;}
bool operator<(const data &a)const {return d < a.d;}
}a[2007010] , q[100010];
double px[2010] , py[2010] , pr[2010];
int f[2010] , ans[100010] , tot;
int find(int x)
{
return x == f[x] ? x : f[x] = find(f[x]);
}
int main()
{
int n , m , i , j , p = 1 , t1 , t2 , t3 , t4;
double w , h;
scanf("%d%d%lf%lf" , &n , &m , &w , &h);
for(i = 1 ; i <= n ; i ++ )
{
scanf("%lf%lf%lf" , &px[i] , &py[i] , &pr[i]);
a[++tot] = data(px[i] - pr[i] , i , n + 1);
a[++tot] = data(py[i] - pr[i] , i , n + 2);
a[++tot] = data(w - px[i] - pr[i] , i , n + 3);
a[++tot] = data(h - py[i] - pr[i] , i , n + 4);
for(j = 1 ; j < i ; j ++ ) a[++tot] = data(sqrt(squ(px[i] - px[j]) + squ(py[i] - py[j])) - pr[i] - pr[j] , i , j);
}
for(i = 1 ; i <= m ; i ++ ) scanf("%lf%d" , &q[i].d , &q[i].x) , q[i].d *= 2 , q[i].y = i;
sort(a + 1 , a + tot + 1) , sort(q + 1 , q + m + 1);
for(i = 1 ; i <= n + 4 ; i ++ ) f[i] = i;
for(i = 1 ; i <= m ; i ++ )
{
while(p <= tot && a[p].d < q[i].d) f[find(a[p].x)] = find(a[p].y) , p ++ ;
t1 = find(n + 1);
t2 = find(n + 2);
t3 = find(n + 3);
t4 = find(n + 4);
if(q[i].x == 1)
{
ans[q[i].y] |= (1 << 1);
if(t2 != t1 && t2 != t3 && t2 != t4) ans[q[i].y] |= (1 << 2);
if(t1 != t2 && t1 != t3 && t2 != t4 && t3 != t4) ans[q[i].y] |= (1 << 3);
if(t1 != t2 && t1 != t3 && t1 != t4) ans[q[i].y] |= (1 << 4);
}
else if(q[i].x == 2)
{
ans[q[i].y] |= (1 << 2);
if(t2 != t1 && t2 != t3 && t2 != t4) ans[q[i].y] |= (1 << 1);
if(t3 != t1 && t3 != t2 && t3 != t4) ans[q[i].y] |= (1 << 3);
if(t1 != t3 && t1 != t4 && t2 != t3 && t2 != t4) ans[q[i].y] |= (1 << 4);
}
else if(q[i].x == 3)
{
ans[q[i].y] |= (1 << 3);
if(t1 != t2 && t1 != t3 && t2 != t4 && t3 != t4) ans[q[i].y] |= (1 << 1);
if(t3 != t1 && t3 != t2 && t3 != t4) ans[q[i].y] |= (1 << 2);
if(t4 != t1 && t4 != t2 && t4 != t3) ans[q[i].y] |= (1 << 4);
}
else
{
ans[q[i].y] |= (1 << 4);
if(t1 != t2 && t1 != t3 && t1 != t4) ans[q[i].y] |= (1 << 1);
if(t1 != t3 && t1 != t4 && t2 != t3 && t2 != t4) ans[q[i].y] |= (1 << 2);
if(t4 != t1 && t4 != t2 && t4 != t3) ans[q[i].y] |= (1 << 3);
}
}
for(i = 1 ; i <= m ; i ++ )
{
for(j = 1 ; j <= 4 ; j ++ )
if(ans[i] & (1 << j))
printf("%d" , j);
puts("");
}
return 0;
}
【bzoj5183】[Baltic2016]Park 离线+对偶图+并查集的更多相关文章
- 【bzoj3007】拯救小云公主 二分+对偶图+并查集
题目描述 英雄又即将踏上拯救公主的道路…… 这次的拯救目标是——爱和正义的小云公主. 英雄来到boss的洞穴门口,他一下子就懵了,因为面前不只是一只boss,而是上千只boss.当英雄意识到自己还是等 ...
- bzoj5183 [Baltic2016]Park
题目描述: bz luogu 题解: 把坐标系看反了持续$WA$系列. 对偶图+并查集维护. 先处理出树对树.树对墙的空隙,然后把人和空隙按从小到大排序. 用并查集维护四面墙之间是否能互相隔断. 代码 ...
- BZOJ_4423_[AMPPZ2013]Bytehattan_对偶图+并查集
BZOJ_4423_[AMPPZ2013]Bytehattan_对偶图+并查集 Description 比特哈顿镇有n*n个格点,形成了一个网格图.一开始整张图是完整的. 有k次操作,每次会删掉图中的 ...
- 【BZOJ4423】[AMPPZ2013]Bytehattan 对偶图+并查集
[BZOJ4423][AMPPZ2013]Bytehattan Description 比特哈顿镇有n*n个格点,形成了一个网格图.一开始整张图是完整的.有k次操作,每次会删掉图中的一条边(u,v), ...
- 【bzoj4423】[AMPPZ2013]Bytehattan(平面图转对偶图+并查集)
题目传送门:bzoj4423 如果是普通的删边判连通性,我们可以很显然的想到把操作离线下来,倒着加边.然而,这题强 制 在 线. 虽然如此,但是题目所给的图是个平面图.那么我们把它转成对偶图试试看? ...
- HDU 5441 离线处理 + 并查集
题意:给n个节点m条带权值边的无向图.然后q个问题,每次询问点对的数目,点对需要满足的条件是:1)连通:2)其路径的最大权值不能超过询问值. 分析:如果没次询问一次,dfs一次,很可能超时,因此可以用 ...
- 对偶图 并查集 BZOJ4423
题目链接 题目因为要根据上一次的输出结果来判断这次的输入,也就是要求我们强制在线,不能够把输入全部储存后处理 如果不要求强制在线,我们可以先把所以输入储存起来,从最后开始处理,把删边改成加边,如果在加 ...
- [BZOJ4423][AMPPZ2013]Bytehattan(对偶图+并查集)
建出对偶图,删除一条边时将两边的格子连边.一条边两端连通当且仅当两边的格子不连通,直接并查集处理即可. #include<cstdio> #include<algorithm> ...
- hdu Portal(离线,并查集)
题意:在一张无向图上,已知边权,做q组询问,问小于L的点对共有几组.点对间的距离取=min(两点之间每一条通路上的最大值). 分析:这里取最大值的最小值,常用到二分.而这里利用离线算法,先对边从小到大 ...
随机推荐
- IDEA 运行报错 failed to create a child event loop
背景 在IDEA中写了测试代码,但是运行的时候一直提示 java.lang.IllegalStateException: failed to create a child event loop ... ...
- 【转载】C/C++杂记:深入虚表结构
原文:C/C++杂记:深入虚表结构 1. 虚表与“虚函数表” 在“C/C++杂记:虚函数的实现的基本原理”一文中曾提到“虚函数表”的概念,只是为了便于理解,事实是:虚函数表并不真的独立存在,它只是虚表 ...
- 【BZOJ4803】逆欧拉函数
[BZOJ4803]逆欧拉函数 题面 bzoj 题解 题目是给定你\(\varphi(n)\)要求前\(k\)小的\(n\). 设\(n=\prod_{i=1}^k{p_i}^{c_i}\) 则\(\ ...
- svn 冲突处理
C:\workspace\test>svn upConflict discovered in 'test.txt'.Select: (p) postpone, (df) diff-full, ( ...
- 远程连接ejabberd的mnesia数据库
由于服务器是server版本,所以很难直观的看到mnesia的数据.所以对于初学者来说非常的困惑. 特地在qq群中请教了别人.别人说只要pong通了就行,就能通过rpc去操作远程的mnesia数据库. ...
- springAOP之代理模式
springAOP指的是在spring中的AOP,什么是AOP,相对于java中的面向对象(oop),在面向对象中一些公共的行为,像日志记录,权限验证等如果都使用面向对象来做,会在每个业务方法中都写上 ...
- 提取验证码到winform上webbroswer和axwebbroswer
在网上只有webbroswer的代码,所以自己又修改了修改改成axwebbroswer的 public static class yanZhengMaHelp { //webbrowser验证码 pu ...
- [二读]The Art of Pompeii's Influence on Neo-Classicism
The Art of Pompeii's Influence on Neo-Classicism The discovery of Pompeii's ruins in 1599 profoundly ...
- Unity3D:Text在Inspector面板中中无法显示,需转换成UTF-8格式
环境:Win10 读取text内容后unity报错:Input string was not in the correct format 同时在Inspector面板中无法预览Text文本内容 随后发 ...
- 设计模式C++实现
准备写一系列笔记用来记录学习设计模式的过程,同时写出自己对几种主要的设计模式的理解,以及编码实现,同时总结. 主要参考书籍就是 <Head First Design Patterns>这本 ...