2019ACM河北省省赛——Battle of Balls

编程入门 行业动态 更新时间:2024-10-27 00:24:03

2019ACM<a href=https://www.elefans.com/category/jswz/34/1731571.html style=河北省省赛——Battle of Balls"/>

2019ACM河北省省赛——Battle of Balls

题目描述
Now that you have a ball of radius r, you want it to go from the bottom boundary of the map to the top boundary of the map (starting and ending points can be considered outside the map, entering the map from the bottom boundary and leaving the map from the top boundary). But there are a lot of little spikes in the map, and we can think of them as points. Your ball can’t touch any of the points and the left or the right boundary of the map, even if the edge of the ball can’t touch them. The area of the map can be seen as 100 \times 100100×100, with the lower left corner (0,0)and the upper right corner (100,100). The bottom boundary is y = 0, and the top boundary is y = 100.
输入描述:
The first line contains an integer T, representing the number of data sets.
After that, there were T sets of data. In each set:
The first line contains an integer n ,which represents the number of small spikes, and a floating point number r, which is your ball’s radius.
The next n lines, each line containing two floating point numbers x,y, representing the coordinates of the spikes.
1001≤T≤100, 0 ≤n≤1000 , 0 ≤r≤1000, 0≤x,y≤100
输出描述:
For each set of input, if the ball can reach the top boundary of the map, output Yes ; Otherwise, output No.
示例1
输入

1
1 25.0
50.0 50.0

输出

No

思路
借鉴大佬
并查集,看的别人的
这个做法是有尖刺的地方若距离小于r,那么将其连通起来。
判断距离是否小于r 的时候要注意比较的数据是double
这题整了半天然后,然后一直示测试样例通过0%,一行一行找错发现把数组fa[1001],改成fa[1002]就对了。
代码

#include<bits/stdc++.h>
#define eps 1e-8
using namespace std;
double x[1010],y[1010];
int fa[1002];
int find(int x){if(fa[x]==-1) return x;else{fa[x]=find(fa[x]);return fa[x];}
}
void merge(int a,int b){int x=find(a);int y=find(b);if(x!=y) fa[x]=y;
}
double dis(int a,int b){double d=hypot(x[a]-x[b],y[a]-y[b]);return d;
}
int main(){int T;cin>>T;while(T--){memset(fa,-1,sizeof(fa));int n;double r;cin>>n>>r;r*=2.0;for(int i=1;i<=n;i++){cin>>x[i]>>y[i];if(x[i]-r<=0) merge(0,i);if(100-x[i]-r<=0) merge(i,n+1);}for(int i=1;i<=n;i++){for(int j=i+1;j<=n;j++){if(dis(i,j)-r<=eps) merge(i,j); }}if(find(0)==find(n+1)) cout<<"No"<<endl;else cout<<"Yes"<<endl;}return 0;
} 

更多推荐

2019ACM河北省省赛——Battle of Balls

本文发布于:2024-02-17 05:35:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1692833.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:河北省   ACM   Battle   Balls

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!