PUBG is a multiplayer online battle royale video game. In the game, up to one hundred players parachute onto an island and scavenge for weapons and equipment to kill others while avoiding getting killed themselves. BaoBao is a big fan of the game, but this time he is having some trouble selecting the safest building.
There are buildings scattering on the island in the game, and we consider these buildings as points on a two-dimensional plane. At the beginning of each round, a circular safe area whose center is located at (0, 0) with radius will be spawned on the island. After some time, the safe area will shrink down towards a random circle with radius (). The whole new safe area is entirely contained in the original safe area (may be tangent to the original safe area), and the center of the new safe area is uniformly chosen within the original safe area.
The buildings covered by the new safe area is called the safe buildings. Given the radius of the safe areas and the positions of the buildings, BaoBao wants to find all the buildings with the largest probability to become safe buildings.
Input
There are multiple test cases. The first line of input contains an integer , indicating the number of test cases. For each test case:
The first line contains three integers (), and (), indicating the number of buildings and the radius of two safe circles.
The following lines each contains 2 integers and (), indicating the coordinate of the buildings. Here we assume that the center of the original safe circle is located at , and all the buildings are inside the original circle.
It's guaranteed that the sum of over all test cases will not exceed 5000.
Output
For each test case output two lines.
The first line contains an integer , indicating the number of buildings with the highest probability to become safe buildings.
The second line contains integers separated by a space in ascending order, indicating the indices of safest buildings.
Please, DO NOT output extra spaces at the end of each line.
Sample Input
2 3 10 5 3 4 3 5 3 6 3 10 4 -7 -6 4 5 5 4
Sample Output
1 1 2 2 3
题意很简单,就是依据“绝地求生”(吃鸡)写的一道数学几何题。在以(0,0)为原点,R为半径的区域内有n个建筑,求在下一次缩圈为半径 r 时,建筑的安全概率。这个半径为 r 的圈随机出现在半径为R的圈内。
题解:怎么求概率?
对于一幢建筑(或者说一个点),以其为圆心,做一个以半径为 2r 的圆Q;
圆Q在圆O内的面积,除以圆O的面积,得到的商即为这个点对应的概率。
显然这个概率,有关于:“点和原点的距离”;
1.当R>2*r 时,
在以原点为圆心,以R-2*r为半径的圆的范围内的点,安全概率最高且全部相同;
如果不存在这样的点,则越靠近原点越安全;
2.当R<=2*r时,
在以原点为圆心,以2*r-R为半径的圆的范围内的点,安全概率最高且全部相同;
如果不存在这样的点,则越靠近原点越安全;
贴代码
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn = 10005;
int n,R,r;
struct Node{
double x,y,c;
int index;
}a[maxn];
bool cmp(Node a,Node b){
return a.c < b.c;
}
bool cmp1(Node a,Node b){
return a.index < b.index;
}
int main()
{
int t;
cin>>t;
while(t--){
cin>>n>>R>>r;
for(int i = 0;i < n;i++){
cin>>a[i].x>>a[i].y;
a[i].c = a[i].x*a[i].x + a[i].y*a[i].y;
a[i].index = i+1;
}
sort(a,a+n,cmp);
if(R > 2*r){
int ans = 0;
int t = (R - 2*r)*(R - 2*r);
for(int i = 0;i < n;i++){
if(a[i].c <= t){
ans++;
}
}
if(ans > 0){
sort(a,a+ans,cmp1);
cout<<ans<<endl;
cout<<a[0].index;
for(int i = 1;i < ans;i++)
cout<<" "<<a[i].index;
cout<<endl;
continue;
}else if(ans == 0){
int te = 0;
for(int i = 0;i < n;i++){
te++;
if(a[i].c < a[i+1].c)
break;
}
sort(a,a+te,cmp1);
cout<<te<<endl;
cout<<a[0].index;
for(int i = 1;i < te;i++)
cout<<" "<<a[i].index;
cout<<endl;
continue;
}
}else{
int ans = 0;
int t = (2*r-R)*(2*r-R);
for(int i = 0;i < n;i++){
if(a[i].c <= t){
ans++;
}
}
if(ans > 0){
sort(a,a+ans,cmp1);
cout<<ans<<endl;
cout<<a[0].index;
for(int i = 1;i < ans;i++)
cout<<" "<<a[i].index;
cout<<endl;
continue;
}else if(ans == 0){
int te = 0;
for(int i = 0;i < n;i++){
te++;
if(a[i].c < a[i+1].c)
break;
}
sort(a,a+te,cmp1);
cout<<te<<endl;
cout<<a[0].index;
for(int i = 1;i < te;i++)
cout<<" "<<a[i].index;
cout<<endl;
continue;
}
}
}
return 0;
}