ZOJ - 3993 - Safest Buildings(概率,分类讨论)

Safest Buildings

Time Limit: 1 Second       Memory Limit: 65536 KB

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.

Input

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 ≤ 100), indicating the number of buildings and the radius of two safe circles.

The following  lines each contains 2 integers xi and yi (-1e4 ≤ xi,yi ≤ 1e4), 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.

Output

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.

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的小圆,小圆的圆心不固定但是小圆一定含于或内切于大圆,大圆内有n个点,问最后这些点中在过了一段时间后还在小圆内的概率最大的是哪些点,按标号从小到大输出



左图中画上阴影部分的圆就是小圆的圆心可以停留的位置,以每个在阴影部分内部的点为圆心画半径为r的圆,该圆于阴影部分重合的面积与总阴影部分面积的总和就是该点最后在小圆内的概率


可以得到距离圆心距离 ≤ |R-2r| 的点的概率相同,均为 1 或 (π*r^2)/(π*(R-r)^2)

当距离在[|R-2r|,R]区间,阴影部分与小圆重合面积会不断减小,所以概率也就会不断的减小

分类讨论一下就行了


#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

const int N = 1e2 + 10;
int T,n,R,r,x,y,dis[N],mi,ans[N],cnt;

int main()
{
    scanf("%d",&T);
    while(T--){
        scanf("%d%d%d",&n,&R,&r);
        mi = 1e9;cnt = 0;
        for(int i=1;i<=n;i++){
            scanf("%d%d",&x,&y);
            dis[i] = x*x + y*y;
            mi = min(dis[i], mi);
        }
        int d = (R-2*r)*(R-2*r);
        if(mi <= d){
            for(int i=1;i<=n;i++){
                if(dis[i]<=d){
                    ans[cnt++] = i;
                }
            }
        }else{
            for(int i=1;i<=n;i++){
                if(dis[i]==mi){
                    ans[cnt++] = i;
                }
            }
        }
        printf("%d\n",cnt);
        for(int i=0;i<cnt;i++){
            printf("%d%c",ans[i],i==cnt-1?'\n':' ');
        }
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值