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. Python脚本之批量复制文件并同时支持重命名

    import os import shutil import time start_time = time.time() # 需要被复制的文件夹 old_path = r'C:\old_dir' ne ...

  2. 零基础入门Vue之窥探大法——计算与侦听

    前言 在 上一小节 我介绍了我学习vue入门 插值语法 的过程. 在本篇,我将记录我对vue的 计算属性和侦听器 的学习记录 注:本篇对于"侦听"和"监听"是一 ...

  3. Intellij IDEA 中 .properties文件中文乱码

    在别的地方显示正常的 application.properties 文件,放到 idea 中就会有乱码,如下图所示 idea 右下角编码那里还是灰色的,不能更改 解决方法 点开 idea 的 sett ...

  4. .NET Core开发实战(第12课:配置变更监听)--学习笔记

    12 | 配置变更监听:配置热更新能力的核心 这一节讲解如何使用代码来监视配置变化并做出一些动作 当我们需要追踪配置发生的变化,可以在变化发生时执行一些特定的操作 配置主要提供了一个 GetReloa ...

  5. ABC 313

    前三题过水. D题 与 5+*的题解 注意:交互题每输出一次,就要 fflush(stdout); 一次 E 其实不是太难,但是赛时一直在搓 D 还没搓出来 首先如果有两个大于 \(1\) 的数相邻, ...

  6. NC51111 Atlantis

    题目链接 题目 题目描述 There are several ancient Greek texts that contain descriptions of the fabled island At ...

  7. Codeforces Round #821 (Div. 2) A-E

    比赛链接 A 题解 知识点:贪心. 下标模 \(k\) 相同分为一组,共有 \(k\) 组,组间不能互换,组内任意互换. 题目要求连续 \(k\) 个数字,一定能包括所有的 \(k\) 组,现在只要在 ...

  8. 【Unity3D】基于AssetBundle实现资源热更新

    1 前言 ​ Unity3D 本地资源一般放在 Resources 目录下,但是 Resouces 文件夹的大小不能超过 2G,使用 AssetBundle 管理资源可以解决 Resources 文件 ...

  9. 【OpenGL ES】Blinn改进的冯氏光照模型

    1 前言 ​ 光照元素主要有环境光(ambient).漫反射光(diffuse).镜面反射光(specular),光照模型主要有冯氏模型和 Blinn 改进的冯氏模型,两者区别在与镜面反射光的计算,冯 ...

  10. 《深入理解Java虚拟机》(七) volatile 变量

    目录 概述 一.内存模型 物理机内存模型 Java内存模型 Java内存模型中有如下的规定: 操作 二.Volatile变量 volatile修改变量后保证所有线程对其可见性 volatile禁止指令 ...