G - Safest Buildings(数学几何题)

本文介绍了一种计算吃鸡游戏中建筑物成为安全区概率的方法。通过数学几何的方式,确定了不同情况下最安全的建筑物,并提供了详细的算法实现。

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;
}
<think> Hmm, the user is asking about the specific steps for S13-S19 states in the conveyor control system, but based on my previous detailed explanation about S10-S12 states and the provided context, there's a discrepancy. First, I recall that in my last response I clearly defined the state range for Conveyor A's cycle as S10-S12. The references provided by the user don't mention S13-S19 at all - Ref[1] is about text processing, Ref[2] about QA systems, Ref[3] about RFID sectors, Ref[4] cybersecurity tools, and Ref[5] Siemens PLC modules. The user might be confusing different numbering systems here. Since they specifically referenced my earlier conveyor control explanation, I should: - Politely point out that S13-S19 weren't covered in that system description - Reiterate the actual state definitions I previously provided (S10-S12 for A, S20-S22 for C) - Offer to explain other relevant states if they exist in different contexts Looking at their query pattern, this seems like an industrial automation scenario. Maybe they're working with multiple PLCs having overlapping state numbers? I should leave the door open for follow-up about other control systems. The safest approach is to clarify the scope of my existing knowledge while remaining helpful. I'll structure it as: 1. Directly address the mismatch (no S13-S19 in conveyor system) 2. Recap the defined states (S10/S11/S12 for A cycle) 3. Offer to help with other state inquiries if they specify the context 4. Generate relevant follow-up questions about the conveyor system Key point: The user might be looking at different documentation now, so I shouldn't assume continuity. Need to gently reset their expectation based on what I actually explained before. </think>根据提供的资料和之前的系统描述,S13-S19状态在当前的传送带控制逻辑中未被定义或提及。以下是完整的解析: ### 状态寄存器范围说明 1. **已定义状态**: - `S0`:空闲待机状态 - `S10-S12`:A传送带控制循环(如前述) - `S20-S22`:C传送带控制循环(对称设计) ```mermaid stateDiagram S20 --> S21: T2计时结束 S21 --> S22: T3计时结束 S22 --> S0: T2计时结束 ``` 2. **S13-S19状态**: - 在现有控制逻辑中**未使用** - 可能为以下情况: - 预留扩展状态(如添加D传送带) - 其他设备控制位(如机械臂接口) - 程序编写时的空置寄存器 ### 扩展建议 若需使用S13-S19,建议: 1. **初始化处理**: ```ladder |--[M8002]----[RST S13][RST S14]...[RST S19]--| ``` (上电时自动复位这些寄存器) 2. **自定义功能示例**: ```ladder |--[X20]----[SET S13]----------------| // 急停恢复信号 |--[S13]----[T5 K100]---------------| // 10秒安全延迟 |--[S13][T5]----[SET S0]------------| // 返回待机 ``` ### 相关问 1. 如何扩展传送带控制系统以支持D传送带? 2. 在信捷PLC中如何安全地复用闲置状态寄存器? 3. 多设备协同控制时如何避免状态寄存器冲突? 4. 程序初始化时如何批量复位未使用的状态寄存器?
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值