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 线段相交+并查集)
先说一下题目大意:给定一些线段,这些线段顺序编号,这时候如果两条线段相交,则把他们加入到一个集合中,问给定一个线段序号,求在此集合中有多少条线段. 这个题的难度在于怎么判断线段相交,判断玩相交之后就是 ...
随机推荐
- PAT甲级——A1155 HeapPaths【30】
In computer science, a heap is a specialized tree-based data structure that satisfies the heap prope ...
- 关于Ext4 extraParams 不能传递动态参数的问题解决办法
可以监听请求发送之前的事件:beforeload ,然后再添加请求的参数 me.store = Ext.create('Ext.data.JsonStore', { remoteSort: true, ...
- log4j基础配置使用
添加log4j的jar包:可以从maven处下载:https://mvnrepository.com/artifact/log4j/log4j/1.2.17 <!-- https://mvnre ...
- easyUI学习笔记二
1. 拖拉大小 <!DOCTYPE html> <html> <head> <title>easyui学习</title> <scr ...
- [Fw]中断的初始化
要使用中断肯定得初始化,这些初始化在系统启动时已经为你做好了,但是我们还是来看看怎样初始化的,这样就能更好的理解中断机制了.先看下面函数: 355 void __init init_ISA_irqs ...
- fiddler抓取手机端的数据流量包
1.首先下载安装fiddler 2.然后打开fiddler,进入到tools-->options-->connections 3.然后进入到https 4.设置完成后,查找本机ip 然后打 ...
- Linux下安装git本地库与服务器端远程库
1. git是一个分布式版本管理系统,关于该工具的详细介绍,我认为廖雪峰老师介绍的非常全面:https://www.liaoxuefeng.com/wiki/896043488029600. 不 ...
- linux下有趣的工具
1.toilet(在CentoOS7 安装) yum install -y https://raw.githubusercontent.com/sliqua-hosting/repo/master/c ...
- Java8 新增BASE64加解密API
什么是Base64编码? Base64是网络上最常见的用于传输8Bit字节码的编码方式之一,Base64就是一种基于64个可打印字符来表示二进制数据的方法 基于64个字符A-Z,a-z,0-9,+,/ ...
- 利用Stream模式进行文件拷贝
const fs = require('fs'); const file = fs.createReadStream("readfile.js"); const outputFil ...