2018 ICPC East-Central NA Regional Practice Contest B-Are You Listening

Are You Listening? Kattis - areyoulistening


CPU Time limit: 1 second
Memory limit: 1024 MB

You’re a top government spy currently at a secret location behind enemy lines (ooooh…exciting!). You have a communication device that allows you to stay in contact with various other operatives that you work with. The broadcast range of the device is adjustable and ideally you would set it at its maximum value to be able to reach the largest number of operatives. Unfortunately, the enemy is not stupid and has a set of listening devices that can detect your signal. These listening devices each have a fixed range (which can vary from device to device), and in order to pinpoint your location the enemy must detect you on at least three of their listening devices. Therefore, you are safe as long as you set your broadcast range so that at most two listening devices can detect you. A listening device can detect you if your broadcast range and its listening range touch at more than one point.

An example situation is shown below. Your device and its broadcast area are shown in the grey circle, and four listening devices and their detecting areas are shown in the white circles. On the far left you have set your broadcast range so that none of the listening devices can detect you, but clearly you could increase your range. In the middle picture you’ve increased it so that two of the listening devices can detect you, but that’s fine. In the right picture, you’ve increased your range too much since now three of the listening devices can detect you.

2018 ICPC East-Central NA Regional Practice Contest B-Are You Listening_第1张图片

Given your location and the locations and detection ranges of a set of listening devices, determine the maximum broadcast range for your communication device. Note that this range may be 0 if the broadcast device it already within the range of three listening devices.

Input

Input starts with a line containing three integers cx cy n where (cx,cy) is your location and 3≤n≤100 is the number of listening devices. The next n lines each contain three integers x y r, where (x,y) is the location of a listening device and 0

Output

Display the radius of the maximum broadcast area, rounding down to the nearest integer.
Sample Input 1

90 80 4
60 35 25
50 140 35
195 165 25
195 40 40

Sample Output 1

72

来源:

Author: John Bonomo
Source: 2018 ICPC East-Central NA Regional Practice Contest

题目链接

题意:
求在同时不被三个点以及以上的雷达扫到的情况下,所能探测的最大范围。
解题思路:
这道题数据较小,所以可以直接暴力来测试,计算每个点与自身的距离,然后进行排列,取得最大的距离。但是要注意到,可能自身的点从刚开始就被三个雷达扫到了,就无法进行探测,距离显然为0。

#include 
using namespace std;
int main()
{
    int n;
    int cx,cy;
    double a[100];
    scanf("%d%d%d",&cx,&cy,&n);
    int num=0;
    for(int i=0; i<n; i++)
    {
        int x,y,r;
        scanf("%d%d%d",&x,&y,&r);
        a[i]=sqrt((cx-x)*(cx-x)+(cy-y)*(cy-y))-r;//计算距离并储存起来
        if(a[i]<0)//计算还没有探测便已经被扫到的情况
            num++;
    }
    sort(a,a+n);
    if(num>=3)printf("0\n");//刚开始就被查找到了位置
    else
        printf("%d\n",(int)a[2]);//被第一个与第二个雷达扫到,而第三个扫不到的距离
    return 0;
}

第一次写题解。。。如有不足请见谅

你可能感兴趣的:(C++,简单处理)