当前位置:网站首页>Dojnoip201708 cheese solution
Dojnoip201708 cheese solution
2022-07-28 13:49:00 【bj_ hacker】
DOJNOIP201708 Cheese solution
subject
link
https://deeplearning.org.cn/problem/CCF-1147
Literal description
describe
There's a big piece of cheese , Its height is h, Its length and width can be considered infinite , There are many spherical cavities with the same radius in the middle of the cheese . We can set up a space coordinate system in this cheese , In the coordinate system , The bottom surface of the cheese is z = 0, The top surface of the cheese is z = h. Now? , There is a little mouse on the bottom of the cheese Jerry, It knows the coordinates of all the hollow centers in the cheese . If two cavities are tangent or intersect , be Jerry You can run from one hole to another , Specially , If a cavity is tangent to or intersects the lower surface ,Jerry You can run from the bottom of the cheese into the void ; If A void is tangent to or intersects the upper surface ,Jerry You can go from the void to the top of the cheese . On the lower surface of cheese Jerry Want to know , Without destroying the cheese , Can you use the existing cavity to run to the upper surface of the cheese ? Two points in space P1(x1,y1,z1)、P2(x2,y2,z2) The formula of distance is as follows :
dist(P1,P2)=sqrt((x1−x2)2+(y1−y2)2+(z1−z2)2)
This is the explanation of the following example :
Input description
Enter the file name as cheese.in. Each input file contains multiple sets of data . The first line of the input file , Contains a positive integer T, Represents the number of data groups contained in the input file . Next is T Group data , The format of each group of data is as follows : The first line contains three positive integers n,h and r, The two numbers are separated by a space , They stand for cheese The number of holes , The height of the cheese and the radius of the void . Next n That's ok , Each line contains three integers x、y、z, The two numbers are separated by a space , Said empty The coordinates of the center of the hole are (x,y,z).
Output description
The output file name is cheese.out. The output file contains T That's ok , They correspond to each other T The answer to group data , If in the first place i In group data ,Jerry You can do it from below The surface runs to the upper surface , The output “Yes”, If not , The output “No” ( No quotation marks ).
Use case input 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
Use case output 1
Yes
No
Yes
Tips
Sample explanation :
about 20% The data of ,n = 1,1 ≤ h , r ≤ 10,000, The absolute value of the coordinates does not exceed 10,000.
about 40% The data of ,1 ≤ n ≤ 8, 1 ≤ h , r ≤ 10,000, The absolute value of the coordinates does not exceed 10,000.
about 80% The data of , 1 ≤ n ≤ 1,000, 1 ≤ h , r ≤ 10,000, The absolute value of the coordinates does not exceed 10,000.
about 100% The data of ,1 ≤ n ≤ 1,000,1 ≤ h , r ≤ 1,000,000,000,T ≤ 20, The absolute value of the coordinates does not exceed 1,000,000,000.
Code implementation
#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;
}
边栏推荐
- POJ1860货币兑换题解
- R语言使用lm函数构建多元回归模型(Multiple Linear Regression)、并根据模型系数写出回归方程、使用confint函数给出回归系数的95%置信区间
- Better and more modern terminal tools than xshell!
- Intra prediction and transform kernel selection based on Neural Network
- Today's sleep quality record 75 points
- R语言使用lm函数构建线性回归模型、使用subset函数指定对于数据集的子集构建回归模型(使用floor函数和length函数选择数据前部分构建回归模型)
- 微信小程序中自定义模板
- 111. The sap ui5 fileuploader control realizes local file upload and encounters a cross domain access error when receiving the response from the server
- Humiliation, resistance, reversal, 30 years, China should win Microsoft once
- C语言:优化后的归并排序
猜你喜欢

Strict mode -- let and const -- arrow function -- Deconstruction assignment -- string template symbol -- set and map -- generator function

111. The sap ui5 fileuploader control realizes local file upload and encounters a cross domain access error when receiving the response from the server

30天刷题计划(四)

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

How to check if the interface cannot be adjusted? I didn't expect that the old bird of the 10-year test was planted on this interview question

30 day question brushing plan (II)

The domestic API management tool eolink is very easy to use, creating an efficient research and development tool

产品经理:岗位职责表

使用 IPtables 进行 DDoS 保护

基于神经网络的帧内预测和变换核选择
随机推荐
Go language - Application of stack - expression evaluation
我秃了!唯一索引、普通索引我该选谁?
C语言:归并排序
111. SAP UI5 FileUploader 控件实现本地文件上传,接收服务器端的响应时遇到跨域访问错误
DOJP1520星门跳跃题解
Li Kou sword finger offer 51. reverse order pairs in the array
DDoS protection with iptables
Poj3275 ranking the cows
C language: quick sorting of sequential storage structure
Use non recursive method to realize layer traversal, preorder traversal, middle order traversal and post order traversal in binary tree
使用 Fail2ban 保护 Web 服务器免受 DDoS 攻击
Volcanic stone investment Zhang Suyang: hard technology, the relatively certain answer in the next 10 years
Tutorial on the principle and application of database system (058) -- MySQL exercise (2): single choice question
What is the reason why the words behind word disappear when typing? How to solve it?
.NET的求复杂类型集合的差集、交集、并集
Map tiles: detailed explanation of vector tiles and grid tiles
Rolling update strategy of deployment.
Can second uncle cure young people's spiritual internal friction?
算法---不同路径(Kotlin)
I miss the year of "losing" Li Ziqi