题目链接: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(圆相交+并查集)的更多相关文章

  1. poj 1127:Jack Straws(判断两线段相交 + 并查集)

    Jack Straws Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2911   Accepted: 1322 Descr ...

  2. hdu 1558 线段相交+并查集

    题意:要求相交的线段都要塞进同一个集合里 sol:并查集+判断线段相交即可.n很小所以n^2就可以水过 #include <iostream> #include <cmath> ...

  3. [poj 1127]Jack Straws[线段相交][并查集]

    题意: 给出一系列线段,判断某两个线段是否连通. 思路: 根据线段相交情况建立并查集, 在同一并查集中则连通. (第一反应是强连通分量...实际上只要判断共存即可, 具体的方向啊是没有关系的..) 并 ...

  4. TZOJ 1840 Jack Straws(线段相交+并查集)

    描述 In the game of Jack Straws, a number of plastic or wooden "straws" are dumped on the ta ...

  5. poj 1127(直线相交+并查集)

    Jack Straws Description In the game of Jack Straws, a number of plastic or wooden "straws" ...

  6. HDU 1558 Segment set( 判断线段相交 + 并查集 )

    链接:传送门 题意:输入一个数 n 代表有 n 组操作,P 是在平面内加入一条线段,Q x 是查询第 x 条线段所在相交集合的线段个数 例如:下图 5 与 1.2 相交,1 与 3 相交,2 与 4 ...

  7. poj 1127 -- Jack Straws(计算几何判断两线段相交 + 并查集)

    Jack Straws In the game of Jack Straws, a number of plastic or wooden "straws" are dumped ...

  8. TTTTTTTTTTTTTT poj 1127 Jack Straws 线段相交+并查集

    题意: 有n个木棍,给出木棍的两个端点的x,y坐标,判断其中某两个线段是否连通(可通过其他线段连通) #include <iostream> #include <cstdio> ...

  9. 判断线段相交(hdu1558 Segment set 线段相交+并查集)

    先说一下题目大意:给定一些线段,这些线段顺序编号,这时候如果两条线段相交,则把他们加入到一个集合中,问给定一个线段序号,求在此集合中有多少条线段. 这个题的难度在于怎么判断线段相交,判断玩相交之后就是 ...

随机推荐

  1. 解决 ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'

    原文链接:https://blog.csdn.net/sea_snow/article/details/82498791 感谢原作者大大  提示:ERROR 1044 (42000): Access ...

  2. PAT甲级【2019年3月考题】——A1157 Anniversary【25】

    Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the celebrat ...

  3. Qt Creator 中的插件Plugin, 区分说明。。。

    Qt Creator 中可以创建 三中类型的插件Plugin: 1.用的最多的,派生自QGenericPlugin类: 在新建Library,   Plugin类型工程中,新建. 调用使用QPlugi ...

  4. 关于deepin下安装ssh以后root用户登陆报错的解决

    最近刚刚接触到deepin,觉得,wow,除了mac,还有这么好看的非win系统,而且第测出那个Linux,宽容度很高,非常适合我这种比较喜欢折腾的人,于是下载了deepin15版本并将其当作虚拟机成 ...

  5. HMTL5滑动块研究

    滑动块图片 html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> &l ...

  6. css设置图片的高等于图片的高

    <div class="box"> <img src="img/2222.jpg" /> </div> .box { pos ...

  7. 讲真,下次打死我也不敢随便改serialVersionUID了

    讲真,下次打死我也不敢随便改serialVersionUID了 码农沉思录 码农沉思录 微信号 code-thinker 功能介绍 笔者为国内某知名企业不知名码农,专注Java Web领域多年,有丰富 ...

  8. java中多种方式解析xml

    第一种:DOM.DOM的全称是Document Object Model,也即文档对象模型.在应用程序中,基于DOM的XML分析器将一个XML文档转换成一个对象模型的集合(通常称DOM树),应用程序正 ...

  9. 二、spring的IoC

    IoC的基本认识 Inversion of Control:控制反转,就是将对象的创建权反转交给spring IoC的好处 传统方式的程序编写,底层的实现切换了,需要修改源代码 使用spring之后, ...

  10. spring mvc 整合 druid

    环境: ubuntu eclipse maven 一. pom.xml 加入druid 依赖 <!-- https://mvnrepository.com/artifact/com.alibab ...