Safest Buildings ZOJ - 3993 (几何问题)

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

 

题意:PUBG,,,一个大的安全区,然后给你第一次缩圈的半径,然后每个点为新圈圆心的概率相同,然后给你n个建筑物的坐标,问有几个建筑物是最大可能在新的安全区里的,依次输出来。


思路:当2*r>R时,中间的小圆里的建筑物最有可能且概率为1

 

当2*r<=R时,左边的小圆是新安全区的边界情况,与小圆相切的右边的圆里的建筑物的概率最大且为1

 

 

比较的时候,可以比较点到圆心的距离的平方是否在所述的两个圆里,

由于(2*r-R)*(2*r-R)==(R-2*r)*(R-2*r)

所以可以两种情况合起来写。

详见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
using namespace std;
#define pb push_back
#define INF 0x3f3f3f3f
const int maxn=1e5+5;
struct node{int x, y;} pos[maxn];
vector<int> ans;
int main()
{
    int n,R,r,T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d",&n,&R,&r);
        ans.clear();
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d",&pos[i].x,&pos[i].y);
        }
        int minn=INF;
        for(int i=1;i<=n;i++)
        {
            //如果在符合条件的圆内,就取符合条件的圆的半径的平方,如果不在,就取此点到圆心的距离的平方
            int temp=max((R-2*r)*(R-2*r),pos[i].x*pos[i].x+pos[i].y*pos[i].y);
            minn=min(minn,temp);//使得最大值最小
        }
        for(int i=1;i<=n;i++)
        {
            int temp=max((R-2*r)*(R-2*r),pos[i].x*pos[i].x+pos[i].y*pos[i].y);
            if(minn==temp)//如果和最大值相等,就是概率最大的建筑
                ans.pb(i);
        }
        printf("%d\n",ans.size());
        for(int i=0;i<ans.size();i++)
            printf("%d%c",ans[i]," \n"[i==ans.size()-1]);
    }



    return 0;
}

 

全部评论

相关推荐

不亏是提前批,神仙打架,鼠鼠不配了
站队站对牛:现在92都报工艺岗了
投递韶音科技等公司7个岗位
点赞 评论 收藏
分享
06-27 12:54
已编辑
门头沟学院 Java
累了,讲讲我的大学经历吧,目前在家待业。我是一个二本院校软件工程专业。最开始选专业是觉得计算机感兴趣,所以选择了他。本人学习计算机是从大二暑假结束开始的,也就是大三开始。当时每天学习,我个人认为Java以及是我生活的一部分了,就这样持续学习了一年半,来到了大四上学期末,大概是在12月中旬,我终于找的到了一家上海中厂的实习,但我发现实习生的工作很枯燥,公司分配的活也不多,大多时间也是自己在自学。就这样我秋招末才找到实习。时间来到了3月中旬,公司说我可以转正,但是转正工资只有7000,不过很稳定,不加班,双休,因为要回学校参加答辩了,同时当时也是心高气傲,认为可以找到更好的,所以放弃了转正机会,回学校准备论文。准备论文期间就也没有投递简历。然后时间来到了5月中旬,这时春招基本也结束了,然后我开始投递简历,期间只是约到了几家下场面试。工资也只有6-7k,到现在我不知道该怎么办了。已经没有当初学习的心劲了,好累呀,但是又不知道该干什么去。在家就是打游戏,boss简历投一投。每天日重一次。26秋招都说是针对26届的人,25怎么办。我好绝望。要不要参加考公、考研、央国企这些的。有没有大佬可以帮帮我。为什么感觉别人找工作都是顺其自然的事情,我感觉自己每一步都在艰难追赶。八股文背了又忘背了又忘,我每次都花很长时间去理解他,可是现在感觉八股、项目都忘完了。真的已经没有力气再去学习了。图片是我的简历,有没有大哥可以指正一下,或者说我应该走哪条路,有点不想在找工作了。
码客明:太累了就休息一下兄弟,人生不会完蛋的
如果实习可以转正,你会不...
点赞 评论 收藏
分享
06-12 17:46
门头沟学院 Java
运营你豪哥:来说重点: ​1.项目前置,时间倒序。​​ 2.​项目描述强化结果与量化效果(STAR原则里的R)。​​ ​3.个人技能精炼,明确掌握程度,突出核心。​​ ​4.增加强有力开头的个人总结部分。​​ 5.​优化教育背景(成绩排名)、合并奖项与活动。​​
听劝,我这个简历该怎么改...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务