Safest Buildings (思维)

链接:https://ac.nowcoder.com/acm/problem/14377
来源:牛客网
 

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 n 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 R will be spawned on the island. After some time, the safe area will shrink down towards a random circle with radius r(r ≤ R). 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.

输入描述:

 

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

 

The first line contains three integers n (1 ≤ n ≤ 100),R and r(1 ≤ r ≤ R ≤ 104) , indicating the number of buildings and the radius of two safe circles.

 

The following n lines each contains 2 integers xi and yi (−104 ≤ xi,yi ≤ 104) ,indicating the coordinate of the buildings. Here we assume that the center of the original safe circle is located at (0,0) , and all the buildings are inside the original circle.

 

It's guaranteed that the sum of  n over all test cases will not exceed 5000.

输出描述:

For each test case output two lines.
The first line contains an integer m, indicating the number of buildings with the highest probability to become safe buildings.
The second line contains m  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.

示例1

输入

复制2 3 10 5 3 4 3 5 3 6 3 10 4 -7 -6 4 5 5 4

2
3 10 5
3 4
3 5
3 6
3 10 4
-7 -6
4 5
5 4

输出

复制1 1 2 2 3

1
1
2
2 3

题意:

给出n幢建筑,每个都以一个点表示,给出点坐标。

有一个以原点为圆心,以R为半径的圆,记为圆O,是原始安全范围;

then,安全范围变为在原来那个圆内任意位置的以r为半径的圆(不会超出原来的圆),记为圆P;

求缩圈后,仍在安全范围内的概率最大的,所有的点。

 思路:

怎么求概率?

对于一幢建筑(或者说一个点),以其为圆心,做一个以半径为2r的圆Q;

圆Q在圆O内的面积,除以圆O的面积,得到的商即为这个点对应的概率。

显然这个概率,有关于:“点和原点的距离”;

当R>2*r 时,

在以原点为圆心,以R-2*r为半径的圆的范围内的点,安全概率最高且全部相同;

如果不存在这样的点,则越靠近原点越安全;

当R<=2*r时,

在以原点为圆心,以2*r-R为半径的圆的范围内的点,安全概率最高且全部相同;

如果不存在这样的点,则越靠近原点越安全;

思路转自:https://www.cnblogs.com/dilthey/p/7788017.html

AC代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#define cla(a, sum) memset(a, sum, sizeof(a))
#define rap(i,m,n) for(i=m;i<=n;i++)
#define rep(i,m,n) for(i=m;i>=n;i--)
using namespace std;
typedef long long ll;
typedef pair<ll,ll>P;
const int Inf=0x3f3f3f3f;
const double eps=1e-8;
const int maxn=105;
const ll mod=10007;

int T;
int n,R,r;
struct node{
	int val;
	int id;
}f[maxn];
vector<int>p;

int getsum(int x,int y)
{
	return x*x+y*y;
}

int main()
{
	cin>>T;
	while(T--)
	{
		scanf("%d%d%d",&n,&R,&r);
		int i,j,k;
		p.clear() ;
		rap(i,1,n)
		{
			scanf("%d%d",&j,&k);
			f[i].val =getsum(j,k);
			f[i].id =i;
		 } 
		int mx=1e9+7,temp;
		if(2*r>R)
		{
			j=2*r-R;
			j=j*j;
		    rap(i,1,n){
				temp=f[i].val ;
				if(temp<=j)temp=0;
				if(temp<mx){
					mx=temp;
					p.clear() ;
					p.push_back(i); 
				}
				else if(temp==mx){
					p.push_back(i); 
				}
			}
		}
		else{
			j=R-2*r;
			j=j*j;
			rap(i,1,n){
				temp=f[i].val ;
				if(temp<=j)temp=0;
				if(temp<mx){
					mx=temp;
					p.clear() ;
					p.push_back(i); 
				}
				else if(temp==mx){
					p.push_back(i); 
				}
			}
		}
		j=p.size() ;
		printf("%d\n",j);
		rap(i,0,j-1){
			printf("%d",p[i]);
			if(i<j-1)printf(" ");
		}
		printf("\n");
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值