J. The Volcano Eruption(圆相交+并查集)
题目链接:https://codeforces.com/gym/101915/problem/J
思路:将所有相交的圆用并查集维护看做一个整体,然后枚举每个整体的左边界和右边界,判断能不能同时覆盖整个路。
AC代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + ;
int n;
struct circle{
ll x, y, r;
};
circle c[maxn];
bool intercircle(circle a, circle b)
{
ll d = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
ll r = a.r + b.r;
if(d <= r * r) return true;
else return false;
}
int far[maxn], L[maxn], R[maxn];
int find(int x)
{
if(far[x] == x) return x;
else return far[x] = find(far[x]);
}
void unite(int x, int y)
{
x = find(x);
y = find(y);
if(x == y) return;
far[x] = y;
}
void init(int n)
{
for(int i = ;i <= n;i++)
{
far[i] = i;
L[i] = R[i] = ;
}
}
int main()
{
std::ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--)
{
ll w, l;
cin >> n >> w >> l;
init(n);
for(int i = ;i < n;i++) cin >> c[i].x >> c[i].y >> c[i].r;
for(int i = ;i < n;i++)
{
for(int j = ;j < i;j++)
{
if(intercircle(c[i],c[j])) unite(i, j);
}
}
for(int i = ;i < n;i++)
{
if(c[i].x - c[i].r <= ) L[find(i)] = ;
if(c[i].x + c[i].r >= w) R[find(i)] = ;
}
int ans = ;
for(int i = ;i < n;i++)
{
if(L[i] && R[i]) ans++;
}
cout << ans << endl;
}
return ;
}
最近又做了一道从左上角走到右下角的:那么就会多了俩个方向的约数条件:GYM12346A
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 +;
typedef long long ll;
int n;
struct circle{
ll x, y, r;
};
circle c[maxn];
bool intercircle(circle a, circle b)
{
ll d = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
ll r = a.r + b.r;
if(d <= r * r) return true;
else return false;
}
int far[maxn], L[maxn], R[maxn], U[maxn], D[maxn];
int find(int x)
{
if(far[x] == x) return x;
else return far[x] = find(far[x]);
}
void unite(int x, int y)
{
x = find(x);
y = find(y);
if(x == y) return;
far[x] = y;
U[y] = max(U[x], U[y]);
D[y] = min(D[x], D[y]);
L[y] = min(L[x], L[y]);
R[y] = max(R[x], R[y]);
}
void init(int n)
{
for(int i = ;i <= n;i++)
{
far[i] = i;
L[i] = R[i] = D[i] = U[i] =;
}
}
int main()
{
std::ios::sync_with_stdio(false);
ll n, m, k;
cin >> m >> n >> k;
init(k);
for(int i = ;i <= k;i++)
{
cin >> c[i].x >> c[i].y >> c[i].r;
U[i] = c[i].y + c[i].r;
D[i] = c[i].y - c[i].r;
L[i] = c[i].x - c[i].r;
R[i] = c[i].x + c[i].r;
}
for(ll i = ; i <= k; i++){
for(ll j = i+; j <= k; j++){
if(intercircle(c[i],c[j])) unite(i, j);
}
}
int flag = ;
for(ll i = ; i <= k; i++)
{
if(far[i])
{
if((U[i] >= n && D[i] <= ) ||(L[i] <= && R[i] >= m) ||
(D[i] <= && L[i] <= ) ||(U[i] >= n && R[i] >= m))
{
flag = ;
break;
}
}
}
if(flag) cout <<"N"<<endl;
else cout <<"S"<<endl;
return ;
}
J. The Volcano Eruption(圆相交+并查集)的更多相关文章
- poj 1127:Jack Straws(判断两线段相交 + 并查集)
Jack Straws Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2911 Accepted: 1322 Descr ...
- hdu 1558 线段相交+并查集
题意:要求相交的线段都要塞进同一个集合里 sol:并查集+判断线段相交即可.n很小所以n^2就可以水过 #include <iostream> #include <cmath> ...
- [poj 1127]Jack Straws[线段相交][并查集]
题意: 给出一系列线段,判断某两个线段是否连通. 思路: 根据线段相交情况建立并查集, 在同一并查集中则连通. (第一反应是强连通分量...实际上只要判断共存即可, 具体的方向啊是没有关系的..) 并 ...
- TZOJ 1840 Jack Straws(线段相交+并查集)
描述 In the game of Jack Straws, a number of plastic or wooden "straws" are dumped on the ta ...
- poj 1127(直线相交+并查集)
Jack Straws Description In the game of Jack Straws, a number of plastic or wooden "straws" ...
- HDU 1558 Segment set( 判断线段相交 + 并查集 )
链接:传送门 题意:输入一个数 n 代表有 n 组操作,P 是在平面内加入一条线段,Q x 是查询第 x 条线段所在相交集合的线段个数 例如:下图 5 与 1.2 相交,1 与 3 相交,2 与 4 ...
- poj 1127 -- Jack Straws(计算几何判断两线段相交 + 并查集)
Jack Straws In the game of Jack Straws, a number of plastic or wooden "straws" are dumped ...
- TTTTTTTTTTTTTT poj 1127 Jack Straws 线段相交+并查集
题意: 有n个木棍,给出木棍的两个端点的x,y坐标,判断其中某两个线段是否连通(可通过其他线段连通) #include <iostream> #include <cstdio> ...
- 判断线段相交(hdu1558 Segment set 线段相交+并查集)
先说一下题目大意:给定一些线段,这些线段顺序编号,这时候如果两条线段相交,则把他们加入到一个集合中,问给定一个线段序号,求在此集合中有多少条线段. 这个题的难度在于怎么判断线段相交,判断玩相交之后就是 ...
随机推荐
- cvAddWeighted 进行图片融合
http://blog.csdn.net/longzaitianya1989/article/details/8103822 cvAddWeighted 进行图片融合 2012-10-23 18:2 ...
- SetWindowsHookEx 其他进程的 记录
SetWindowsHookEx( WH_GETMESSAGE,CallWndProc, HInstance, h2); WH_GETMESSAGE 这个类型 hook 其他窗体的 线程是正常的 ...
- SQL 交叉连接与内连接
交叉连接 ,没有任何限制方式的连接. 叫做交叉连接. 碰到一种SQL 的写法. select * from t1,t2 . 这其实是交叉连接 . t1 是三条 , t2 是两条. ...
- laravel 向多视图及所有视图传递数据变量
向单个视图传递变量 1.使用with()方法 : view('user.lists')->with('title',$title); 2.直接view()传参: view('user.lists ...
- 2019-4-8 zookeeper学习笔记
zookeeper学习 ZooKeeper集合中的节点 让我们分析在ZooKeeper集合中拥有不同数量的节点的效果. 如果我们有单个节点,则当该节点故障时,ZooKeeper集合将故障.它有助于“单 ...
- HDU 5159 Card( 计数 期望 )
Card Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- docker-container 操作
1.把container放后台运行 [root@localhost dockerfile3]# docker run bigni/python_flask #默认运行image,container里运 ...
- js返回顶部小Demo
<style> .divH { height: 1800px; } .divT { width: 50px; height: 50px; font-size: 18px; backgrou ...
- js 模板引擎 -Art Template
一个例子涵盖所有: <!doctype html> <html> <head> <meta charset="UTF-8"> < ...
- Java缓冲流的优点和原理
不带缓冲的流的工作原理: 它读取到一个字节/字符,就向用户指定的路径写出去,读一个写一个,所以就慢了. 带缓冲的流的工作原理: 读取到一个字节/字符,先不输出,等凑足了缓冲的最大容量后一次性写出去,从 ...