编程介的小学生 2019-09-14 02:57 采纳率: 20.5%
浏览 191

雷达是怎么计算的,Radar Installation

Description

Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d distance, so an island in the sea can be covered by a radius installation, if the distance between them is at most d.

We use Cartesian coordinate system, defining the coasting is the x-axis. The sea side is above x-axis, and the land side below. Given the position of each island in the sea, and given the distance of the coverage of the radar installation, your task is to write a program to find the minimal number of radar installations to cover all the islands. Note that the position of an island is represented by its x-y coordinates.

Figure A Sample Input of Radar Installations

Input

The input consists of several test cases. The first line of each case contains two integers n (1<=n<=1000) and d, where n is the number of islands in the sea and d is the distance of coverage of the radar installation. This is followed by n lines each containing two integers representing the coordinate of the position of each island. Then a blank line follows to separate the cases.

The input is terminated by a line containing pair of zeros
Output

For each test case output one line consisting of the test case number followed by the minimal number of radar installations needed. "-1" installation means no solution for that case.
Sample Input

3 2
1 2
-3 1
2 1

1 2
0 2

0 0
Sample Output

Case 1: 2
Case 2: 1

  • 写回答

1条回答 默认 最新

  • 依洛(^_^)简 2019-10-31 13:52
    关注

    #include
    #include
    #include
    using namespace std;

    struct Node {
    double left,right;
    } str[1005];

    bool cmp(Node a,Node b) {
    if(a.right==b.right ) {
    return a.left>b.left;
    } else {
    return a.right }
    }
    int main() {
    int n,r,x,y;
    int Case=0;
    while(~scanf("%d %d",&n,&r)&&n&&r) {
    for(int i=0; i scanf("%d %d",&x,&y);
    if(y str[i].left=x-sqrt(r*r-y*y);
    str[i].right=x+sqrt(r*r-y*y);
    } else {
    printf("Case %d: -1\n",++Case);
    }
    }
    sort(str,str+n,cmp);
    double index=str[0].right;
    int num=1;
    for(int i=1; i if(str[i].left>index) {
    index=str[i].right;
    num++;
    }
    }
    printf("Case %d: %d\n",++Case,num);
    }
    return 0;
    }

    评论

报告相同问题?

悬赏问题

  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区