ZOJ 3993 Safest Buildings(概率 数学)

Description

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

题目大意

原先有一个以原点为圆心,以R为半径的圆的安全范围,后来安全范围变为以r为半径的圆,后来的圆的范围最多与原来的圆相切,不能超出。求最终仍在安全范围内的概率最大的所有的点。

解题思路

以某点为圆心,以2*r为半径画圆,可得的面积为判断安全概率大小的依据。
当R>2*r 时,
在以原点为圆心,以R-2*r为半径的圆的范围内的点的安全概率为100%;
若不存在这样的点,越靠近原点,安全概率越大;
当R<=2*r时,
在以原点为圆心,以2*r-R为半径的圆的范围内的点的安全概率为100%;
若不存在这样的点,越靠近原点,安全概率越大。

代码实现

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int ans[107],mark[107];
int main()
{
    int T;
    ll n,R,r;
    ll x,y,num,minn,countt,dis;
    bool flag;
    scanf("%d",&T);
    while(T--)
    {
        num=0;
        countt=0;
        flag=false;
        minn=LLONG_MAX;
        scanf("%lld %lld %lld",&n,&R,&r);
        if(n>2*r)
            dis=(R-2*r)*(R-2*r);
        else
            dis=(2*r-R)*(2*r-R);
        for(int i=0; i<n; i++)
        {
            scanf("%lld %lld",&x,&y);
            if(x*x+y*y<=dis)
            {
                ans[num++]=i+1;
                flag=true;
            }
            if(x*x+y*y<minn)
            {
                countt=0;
                mark[countt++]=i+1;
                minn=x*x+y*y;
            }
            else if(x*x+y*y==minn)
                mark[countt++]=i+1;
        }
        if(flag)
        {
            printf("%d\n",num);
            for(int i=0; i<num; i++)
                printf(i==num-1?"%d\n":"%d ",ans[i]);
        }
        else
        {
            printf("%d\n",countt);
            for(int i=0; i<countt; i++)
                printf(i==countt-1?"%d\n":"%d ",mark[i]);
        }
    }
    return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值