import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader; public class Main {
static int[] rank;
static int[] parent; public static void init(int n) {
rank = new int[n];
parent = new int[n];
for (int i = 0; i < n; i++) {
rank[i] = 1;
parent[i] = i;
}
} public static int find(int x) {
if (parent[x] == x) {
return x;
}
return find(parent[x]);
} public static void union(int x,int y){
int rx = find(x);
int ry = find(y); if( rx == ry){
return;
}
if( rank[rx] >= rank[ry]){
rank[rx] += rank[ry];
parent[ry] = rx;
}else{
rank[ry] += rank[rx];
parent[rx] = ry;
} } public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
long sx, sy, tx, ty;
int n = Integer.valueOf(br.readLine());
String[] words = br.readLine().split("\\s+");
sx = Long.valueOf(words[0]);
sy = Long.valueOf(words[1]);
tx = Long.valueOf(words[2]);
ty = Long.valueOf(words[3]);
long[][] circles = new long[n][3];
for (int i = 0; i < n; i++) {
words = br.readLine().split("\\s+");
long x = Long.valueOf(words[0]);
long y = Long.valueOf(words[1]);
long r = Long.valueOf(words[2]);
circles[i][0] = x;
circles[i][1] = y;
circles[i][2] = r;
} init(n); for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
long[] arr = circles[i];
long[] arr2 = circles[j]; long distance = (arr[0] - arr2[0]) * (arr[0] - arr2[0]) + (arr[1] - arr2[1]) * (arr[1] - arr2[1]);
long dis2 = (arr[2] + arr2[2]) * (arr[2] + arr2[2]);
long dis3 = (arr[2] - arr2[2]) * (arr[2] - arr2[2]);
if( !(distance > dis2) && !(distance < dis3) ){
union(i,j);
}
}
}
//查找在哪个圆上
int srcIndex = 0;
int dstIndex = 0;
for(int i=0;i<circles.length;i++){
long[] arr = circles[i];
long x = arr[0];
long y = arr[1];
long r = arr[2]; if( ( (sx-x)*(sx-x) + (sy-y)*(sy-y)) == r*r){
srcIndex = i;
}
if( ( (tx-x)*(tx-x) + (ty-y)*(ty-y)) == r*r){
dstIndex = i;
}
}
//
if( find(srcIndex) == find(dstIndex)){
System.out.println("Yes");
}else{
System.out.println("No");
} br.close();
} }

【Atcoder D - Circumferences】并查集的更多相关文章

  1. AtCoder Beginner Contest 049 & ARC065 連結 / Connectivity AtCoder - 2159 (并查集)

    Problem Statement There are N cities. There are also K roads and L railways, extending between the c ...

  2. AtCoder Beginner Contest 120 D - Decayed Bridges(并查集)

    题目链接:https://atcoder.jp/contests/abc120/tasks/abc120_d 题意 先给m条边,然后按顺序慢慢删掉边,求每一次删掉之后有多少对(i,j)不连通(我应该解 ...

  3. AtCoder NIKKEI Programming Contest 2019 E. Weights on Vertices and Edges (并查集)

    题目链接:https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_e 题意:给出一个 n 个点 m 条边的无向图,每个点和每 ...

  4. AtCoder Beginner Contest 247 F - Cards // dp + 并查集

    原题链接:F - Cards (atcoder.jp) 题意: 给定N张牌,每张牌正反面各有一个数,所有牌的正面.反面分别构成大小为N的排列P,Q. 求有多少种摆放方式,使得N张牌朝上的数字构成一个1 ...

  5. XJOI 3578 排列交换/AtCoder beginner contest 097D equal (并查集)

    题目描述: 你有一个1到N的排列P1,P2,P3...PN,还有M对数(x1,y1),(x2,y2),....,(xM,yM),现在你可以选取任意对数,每对数可以选取任意次,然后对选择的某对数(xi, ...

  6. Atcoder 2159 連結 / Connectivity(并查集+map乱搞)

    問題文N 個の都市があり.K 本の道路と L 本の鉄道が都市の間に伸びています. i 番目の道路は pi 番目と qi 番目の都市を双方向に結び. i 番目の鉄道は ri 番目と si 番目の都市を双 ...

  7. 【并查集】【set】AtCoder - 2159 - 連結 / Connectivity

    Problem Statement There are N cities. There are also K roads and L railways, extending between the c ...

  8. AtCoder Beginner Contest 177 D - Friends (并查集)

    题意:有\(n\)个人,给你\(m\)对朋友关系,朋友的朋友也是朋友,现在你想要将他们拆散放到不同的集合中,且每个集合中的人没有任何一对朋友关系,问最少需要多少集合. 题解:首先用并查集将朋友关系维护 ...

  9. D - 連結 / Connectivity 并查集

    http://abc049.contest.atcoder.jp/tasks/arc065_b 一开始做这题的时候,就直接蒙逼了,n是2e5,如果真的要算出每一个节点u能否到达任意一个节点i,这不是f ...

  10. BZOJ 4199: [Noi2015]品酒大会 [后缀数组 带权并查集]

    4199: [Noi2015]品酒大会 UOJ:http://uoj.ac/problem/131 一年一度的“幻影阁夏日品酒大会”隆重开幕了.大会包含品尝和趣味挑战两个环节,分别向优胜者颁发“首席品 ...

随机推荐

  1. HBase相关面试题汇总

    1.HBase是什么? (1) HBase一个分布式的基于列式存储的数据库,基于Hadoop的hdfs存储,zookeeper进行管理. (2) HBase适合存储半结构化或非结构化数据,对于数据结构 ...

  2. 使用sqlmap执行SQL注入并获取数据库用户名

    Sqlmap介绍 sqlmap支持MySQL, Oracle,PostgreSQL, Microsoft SQL Server, Microsoft Access, IBM DB2, SQLite, ...

  3. ElasticSearch入门安装与SpringBoot集成实战

    介绍 Elasticsearch 是一个实时分布式搜索和分析引擎,一般用于全文搜索.结构化搜索,分析或者三者混用. 它的底层是基于Apache Lucene(TM)的开源搜索引擎,但是lucene只是 ...

  4. 如何在Windows上使用Git创建一个可执行脚本?

    长话短说,今天介绍如何在windows上使用Git上创建一个可执行的shell脚本. 首先我们要知道windows上Git新添加的文件权限是:-rw-r--r--(对应权限值是644),而通常创建的s ...

  5. 【Android逆向】破解看雪test3.apk方案一

    1. test3.apk 安装到手机 2. 发现其实际逻辑和之前的test2.apk基本一致,逆向so查看到加入了一些检查逻辑 代码: jstring __fastcall fuck(JNIEnv * ...

  6. gitee配置SSH公钥

    第一步,找个地方打开"git bash",然后输入生成ssh公钥的命令: ssh-keygen -t rsa -C 'your-email' 然后敲四次回车生成公钥: 第二步,输入 ...

  7. file.deleteOnExit()与file.delete()的区别

    之前踩过一个坑,下载过的文件在我第二次打开app的时候奇迹的找不到了.难道是没有下载成功?为此我特地查看了我的本地文件路径的目录.事实证明文件的确是下载到了本地路径下,但是第二次进入app的时候,路径 ...

  8. sqlserver数据库jar包下载

    链接:https://pan.baidu.com/s/1mCx5JpVpmU6uUaqMITxP_Q提取码:4piq 说明:若链接失效,联系会及时补上!

  9. 目标检测 - VOC - xml标注格式

    目标检测 - VOC - xml标注格式 相对其他计算机视觉任务,目标检测算法的数据格式更为复杂.为了对数据进行统一的处理,目标检测数据一般都会做成VOC或者COCO的格式. XML标注格式 < ...

  10. 【Azure Fabric Service】怎样关闭 Azure Service Fabric?

    问题描述 怎样关闭Azure Service Fabric服务呢?在Azure门户上没有找到 Stop 按钮. 问题回答 Azure Service Fabric 默认是无法停止的,可以删除. 虽然可 ...