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. (C语言)1到50的阶乘之和列表,参考用,洛谷:P1009 [NOIP1998 普及组] 阶乘之和

    1到50列表,阶乘之和 S=1!+2!+3!+⋯+n!(n≤50) 1::1 2::3 3::9 4::33 5::153 6::873 7::5913 8::46233 9::409113 10:: ...

  2. Google_Book_20Things.前言以及前四项学习笔记

    20 THINGS I LEARNED ABOUT BROWSERS AND THE WEB Illustrated by Christoph Niemann. Written by the Goog ...

  3. ADG备库中某个PDB缺失temp文件

    之前认为缺失的temp文件在开库时会自动创建,但其实也有不能自动创建的场景,alert会有类似如下提示: 2023-05-11T20:35:35.974983+08:00 AWR(6):******* ...

  4. RHEL7安装11204 RAC的注意事项

    最近在某客户的RHEL7 + 11204 RAC环境上测试遇到不少的坑,好在都赶在正式上线前及时发现并处理完毕. 其中两个问题比较典型所以特别记录下:问题都和主机重启后,O相关服务没有自启动导致,看来 ...

  5. TPCH-PostgreSQL生成数据集并导入数据表

    1.数据集下载 TPC-H数据集: https://github.com/gregrahn/tpch-kit 2.解压安装 unzip  tpch-kit-master.zip cd tpch-kit ...

  6. 金仓数据库(kingbase)的system用户被锁的解锁步骤

    今天发现我安装的金仓数据库(kingbase)的system用户被锁了,无法登陆.百度搜了下,使用SUPERMANAGER_V8ADMIN可以解锁,试了下果然如此.解锁步骤如下: 用户:SUPERMA ...

  7. Windows终端的一些配置

    前言 记录早前拿到新的笔记本(win10)后配置命令行的过程,以下是环境: 命令行 : CMD,PowerShell7 Shell :Windows Terminal 设置编码格式(当前代码页)为UT ...

  8. ABC 306

    前三题过水. D \(dp[i][j]\) 表示吃完前 \(i\) 个菜,胃的状况为 \(j\)(\(0\) 是健康,\(1\) 是不好)所获得的最大美味值. E 暴力的平衡树.用 multiset ...

  9. CF1853

    你谷的加题速度实在太慢了 被 CF 的题目薄纱 A 可以选任意次 \(i\in [1,n]\),使 \(a[1\sim i]++,a[i+1\sim n]--\).求最少操作次数使得原数列变成非从小到 ...

  10. MindSponge分子动力学模拟——定义Collective Variables

    技术背景 在前面的几篇博客中,我们介绍了MindSponge分子动力学模拟框架的基本安装和使用和MindSponge执行分子动力学模拟任务的方法.这里我们介绍一个在增强采样领域非常常用的工具:Coll ...