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 线段相交+并查集)
先说一下题目大意:给定一些线段,这些线段顺序编号,这时候如果两条线段相交,则把他们加入到一个集合中,问给定一个线段序号,求在此集合中有多少条线段. 这个题的难度在于怎么判断线段相交,判断玩相交之后就是 ...
随机推荐
- Windows下使用Composer安装yii2
Composer简介 Composer 是PHP中用来管理依赖(dependency)关系的工具.你可以在自己的项目中声明所依赖的外部工具库(libraries),Composer会帮你安装这些依赖的 ...
- 服务端:WCF服务层安全检查核心类
using System.Data; using CSFrameworkV4_5.Common; using CSFrameworkV4_5.Core.SystemSecurity; using CS ...
- Linux 通配符和特殊符号
- LeetCode 实现 Trie (前缀树)
题目链接:https://leetcode-cn.com/problems/implement-trie-prefix-tree/ 题目大意: 略. 分析: 字典树模板. 代码如下: class Tr ...
- Kindeditor在线文本编辑器过滤HTML
KindEditor.ready(function (K) { editor = K.create('textarea[name="content"]', { filterMode ...
- BootStrap 轮播插件(carousel)支持左右手势滑动的方法(三种)
原生的 Bootstrap 的 carousel.js 插件并没有支持手势,有下面3种解决方案 : 1. jQuery Mobile (http://jquerymobile.com/download ...
- 哈希算法和字典类的定义,DataSet中数据遍历的几种方法
哈希算法的基本操作: 1. 哈希表(HashTable)简述 在.NET Framework中,Hashtable是System.Collections命名空间提供的一个容器,用于处理和表现类似 ...
- LAN VLAN与VXLAN学习笔记
一.LAN(Local Area Network,局域网) 1.通信方式: 向目标IP地址发送ARP广播,获取目的IP地址的MAC地址,然后用单播MAC地址实现相互通信 2.LAN的特点: 1.同一L ...
- go语言从例子开始之Example18.struct结构体
Go 的结构体 是各个字段字段的类型的集合.这在组织数据时非常有用 Example: package main import "fmt" type product struct{ ...
- 入门GoldenGate总结
前言 GoldenGate 是oracle官方的一款数据同步产品,类似于msyql的主从复制,配置也稍稍复杂,其中概念一定要搞清楚,不然会被坑的爬不起. 坑 1.数据在线同步(不是指数据初始化),只能 ...