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 线段相交+并查集)
先说一下题目大意:给定一些线段,这些线段顺序编号,这时候如果两条线段相交,则把他们加入到一个集合中,问给定一个线段序号,求在此集合中有多少条线段. 这个题的难度在于怎么判断线段相交,判断玩相交之后就是 ...
随机推荐
- Process Monitor监控进程操作注册表如何实现?
http://zhidao.baidu.com/link?url=Kqav4qkQSprC5FnpHPOGJvhqvY9fJ9-Vdx9g_SWh4w5VOusdRJo4Vl7qIdrG4LwRJvr ...
- H5rem
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1, ...
- FileInputStream_FileOutputStream
Writer的基本方法 //向输出流中写入一个字符数据,该字节数据为参数b的低16位 void write(int c) throws IOException //将一个字符类型的数组中的数据写入输出 ...
- jquery 的几种写法和常见问题
为了理解页面初始化事件的编写和执行方式,特此记录下页面加载事件的语句方式: //最简单的加载事件语句 $(function(){ alert("这个提示框最先弹出")//这个用的最 ...
- QT下载与安装
1.下载地址:https://www.qt.io/download-open-source/ 2.qt5.5:http://download.qt.io/development_releases/qt ...
- 【题解】A Horrible Poem
题目大意 给出一个由小写英文字母组成的字符串 S,再给出 q 个询问,要求回答 S 某个子串的最短循环节. 如果字符串 B 是字符串 A 的循环节,那么 A 可以由 B 重复若干次得到. 输入格式 第 ...
- python字符串有多少字节
是否有一些函数可以告诉我字符串在内存中占用多少字节? 我需要设置套接字缓冲区的大小,以便一次传输整个字符串. 解决方案 import sys sys.getsizeof(s) # getsizeof( ...
- SSOJ 317 Fast Ride
317. Fast Ride Time limit per test: 0.25 second(s) Memory limit: 65536 kilobytes input: standard ou ...
- C#程序的编译过程
C#程序的编译过程,如下图 总结:编译器将C#代码编译成DLL/EXE,DLL/EXE包含metadata(清单数据,对代码的描述)和IL(中间语言),IL(中间语言)经过CLR/JIT第二次编译才是 ...
- Python基础篇(初始函数)
Python初始函数: 一.什么是函数 1.我们到目前为止, 已经可以完成一些软件的基础功能了. 那么我们来完成这样一个功 能: 约x: print("拿出手机") print(& ...