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. yapi的安装

    1.官方网站:https://hellosean1025.github.io 2.看官方的文档,部署方法: 3. 根据文档 安装环境先: 4. 开始安装yapi 5. 可见需要启动一下 6.重启一下 ...

  2. JDK + Tomcat 安装 + 制作自定义镜像【第 2.1 篇 Tomcat 日志满问题】

    更好的方法,跨平台(不依赖平台,比如阿里云的后台)的方法是:spring boot 定时任务,直接在程序里写定时清除日志的任务:以后再说: ============================== ...

  3. JS Leetcode 451. 根据字符出现频率排序题解分析

    壹 ❀ 引 大前天做的一道题,昨天发版到11点,前天聚餐,一直没时间整理,今天下班闲来无事,还是做个简单思路整理.本题来自LeetCode 451. 根据字符出现频率排序,难度中等,其实整理下思路,其 ...

  4. 基于tensorflow的RBF神经网络案例

    1 前言 在使用RBF神经网络实现函数逼近中,笔者介绍了使用 Matlab 训练RBF神经网络.本博客将介绍使用 tensorflow 训练RBF神经网络.代码资源见:RBF案例(更新版) 这几天,笔 ...

  5. Js中Symbol对象

    Js中Symbol对象 ES6引入了一种新的基本数据类型Symbol,表示独一无二的值,最大的用法是用来定义对象的唯一属性名,Symbol()函数会返回symbol类型的值,该类型具有静态属性和静态方 ...

  6. eclipse项目右击找不到build path

    右击项目–>properties–>Project Facets–>勾选右侧的Java,然后保存. 此时再操作就有了.

  7. Redhat6更改yum源

    最近虚拟机中安装了redhat6.3企业版,自带的yum用不起来,软件都找不到. 网上搜了一下说是没付钱...,需要改下yum源.操作步骤如下: 1.切换到yum源存放目录 [root@rhel6 ~ ...

  8. 深入理解Go语言(04):scheduler调度器-GMP里结构体源码分析

    在前面一节中简单介绍了golang的调度模型-GPM模型,介绍了他们各自的作用.这篇文章就来看看他们的源码结构. Go版本:go1.13.9 M结构体 M结构体是OS线程的一个抽象,主要负责结合P运行 ...

  9. Linux驱动开发笔记(三):基于ubuntu的helloworld驱动源码编写、makefile编写以及驱动编译加载流程测试

    前言   前面学习了驱动的基础框架,上一篇编译了gcc7.3.0,那么为了方便很好的熟悉流程,本篇,将使用ubuntu18.04,直接编译ubuntu18.04的驱动,然后做好本篇文章的相关实战测试. ...

  10. windows下redis安装与使用

    下载 redis下载地址 步骤,一直下一步按就完事了,记得勾选添加到环境配置 其中建议自定义路径吧,文件夹名字Redis,一定要大写,小写不来事. 安装完后 启动命令 找到你安装redis的文件夹,在 ...