当前位置:网站首页>DOJNOIP201708奶酪题解
DOJNOIP201708奶酪题解
2022-07-28 12:37:00 【bj_hacker】
题目
链接
https://deeplearning.org.cn/problem/CCF-1147
字面描述
描述
现有一块大奶酪,它的高度为h,它的长度和宽度我们可以认为是无限大的,奶酪中间有许多半径相同的球形空洞。我们可以在这块奶酪中建立空间坐标系,在坐标系中, 奶酪的下表面为z = 0,奶酪的上表面为z = h。 现在,奶酪的下表面有一只小老鼠Jerry,它知道奶酪中所有空洞的球心所在的坐标。如果两个空洞相切或是相交,则 Jerry 可以从其中一个空洞跑到另一个空洞,特别地,如果一个空洞与下表面相切或是相交,Jerry 则可以从奶酪下表面跑进空洞;如果 一个空洞与上表面相切或是相交,Jerry 则可以从空洞跑到奶酪上表面。位于奶酪下表面的 Jerry 想知道,在不破坏奶酪的情况下,能否利用已有的空洞跑到奶酪的上表面去?空间内两点P1(x1,y1,z1)、P2(x2,y2,z2)的距离公式如下:
dist(P1,P2)=sqrt((x1−x2)2+(y1−y2)2+(z1−z2)2)
这个是下面样例的解释:
输入描述
输入文件名为 cheese.in。 每个输入文件包含多组数据。 输入文件的第一行,包含一个正整数 T,代表该输入文件中所含的数据组数。 接下来是 T 组数据,每组数据的格式如下: 第一行包含三个正整数 n,h 和 r,两个数之间以一个空格分开,分别代表奶酪中空 洞的数量,奶酪的高度和空洞的半径。 接下来的 n 行,每行包含三个整数 x、y、z,两个数之间以一个空格分开,表示空 洞球心坐标为(x,y,z)。
输出描述
输出文件名为 cheese.out。 输出文件包含 T 行,分别对应 T 组数据的答案,如果在第 i 组数据中,Jerry 能从下 表面跑到上表面,则输出“Yes”,如果不能,则输出“No” (均不包含引号)。
用例输入 1
3
2 4 1
0 0 1
0 0 3
2 5 1
0 0 1
0 0 4
2 5 2
0 0 2
2 0 4
用例输出 1
Yes
No
Yes
提示
样例说明:
对于20%的数据,n = 1,1 ≤ h , r ≤ 10,000,坐标的绝对值不超过10,000。
对于40%的数据,1 ≤ n ≤ 8, 1 ≤ h , r ≤ 10,000,坐标的绝对值不超过10,000。
对于80%的数据, 1 ≤ n ≤ 1,000, 1 ≤ h , r ≤ 10,000,坐标的绝对值不超过10,000。
对于100%的数据,1 ≤ n ≤ 1,000,1 ≤ h , r ≤ 1,000,000,000,T ≤ 20,坐标的绝对值不超过 1,000,000,000。
代码实现
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e3+10;
int t,n,h,r;
int fa[maxn],x[maxn],y[maxn],z[maxn],a[maxn],b[maxn];
inline int find(int x){
if(x==fa[x])return x;
return fa[x]=find(fa[x]);
}
inline void union_(int x,int y){
int fx1=find(x);
int fy1=find(y);
if(fx1==fy1)return;
else fa[fx1]=fy1;
}
inline double dis(int x1,int y1,int z1,int x2,int y2,int z2){
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
}
signed main(){
scanf("%d",&t);
while(t--){
int cnt1=0,cnt2=0;
scanf("%d%d%d",&n,&h,&r);
for(int i=1;i<=n;i++){
fa[i]=i;
scanf("%d%d%d",&x[i],&y[i],&z[i]);
if(z[i]-r<=0)a[++cnt1]=i;
if(z[i]+r>=h)b[++cnt2]=i;
for(int j=1;j<=i;j++){
if(dis(x[i],y[i],z[i],x[j],y[j],z[j])<=2*r)union_(i,j);
}
}
bool flag=false;
for(int i=1;i<=cnt1;i++){
for(int j=1;j<=cnt2;j++){
if(find(a[i])==find(b[j])){
flag=true;
break;
}
}
if(flag==true)break;
}
if(flag)printf("Yes\n");
else printf("No\n");
}
return 0;
}
边栏推荐
- 屈辱、抗争、逆转,三十年,中国该赢微软一次了
- Blue Bridge Training (additional interview questions) day 7
- Realize the mutual value transfer between main window and sub window in WPF
- 从手机厂高位“出走”的三个男人
- 朋友发来几个面试题
- org.apache.ibatis.exceptions.TooManyResultsException的异常排查过程
- Children's programming electronic society graphical programming level examination scratch Level 2 real problem analysis (judgment question) June 2022
- Gamestop bear market entered NFT trading, and established game retailers took advantage of Web3 to make a second spring
- leetcdoe-342. 4的幂
- 沾上趣店,都得道歉?
猜你喜欢

微念“失去”李子柒的这一年

接口调不通,如何去排查?没想到10年测试老鸟栽在这道面试题上

Countdown 2 days! 2022 China Computing Conference: Mobile cloud invites you to meet with computing network for innovative development

Can second uncle cure young people's spiritual internal friction?

MySQL practice -- master-slave replication

Three men "running away" from high positions in the mobile phone factory

I miss the year of "losing" Li Ziqi

【黑马早报】字节估值缩水,降至2700亿美元;“二舅”视频作者回应抄袭;任泽平称取消商品房预售制是大势所趋;美联储宣布再加息75个基点...

Humiliation, resistance, reversal, 30 years, China should win Microsoft once
![[dark horse morning post] byte valuation has shrunk to $270billion;](/img/58/8d5c78d919ed60bc833ec4daa22e23.jpg)
[dark horse morning post] byte valuation has shrunk to $270billion; "Second uncle" video author responded to plagiarism; Renzeping said that the abolition of the pre-sale system of commercial housing
随机推荐
半波整流点亮LED
docker部署mysql 实现远程连接[通俗易懂]
I'm bald! Who should I choose for unique index or general index?
C语言:随机生成数+快速排序
我抄底了被清算的NFT,却被OpenSea上了锁
朋友发来几个面试题
Customized template in wechat applet
Have you seen the management area decoupling architecture? Can help customers solve big problems
LyScript 获取上一条与下一条指令
【黑马早报】字节估值缩水,降至2700亿美元;“二舅”视频作者回应抄袭;任泽平称取消商品房预售制是大势所趋;美联储宣布再加息75个基点...
Org.apache.ibatis.exceptions.toomanyresultsexception
I copied the bottom of the liquidated NFT, but was locked by opensea
持续(集成--&gt;交付--&gt;部署)
C language: quick sorting of sequential storage structure
JS encapsulation at a glance
[error] after logging in to another machine using SSH, you find that the hostname is still yourself | unable to access yarn8088
验证码暴力破解测试[通俗易懂]
C language: optimized merge sort
数据库系统原理与应用教程(061)—— MySQL 练习题:操作题 21-31(五)
剖析 kubernetes 集群内部 DNS 解析原理