POJ 1328 Radar Installation 贪心
来源:互联网 发布:数字网络广播系统 编辑:程序博客网 时间:2024/06/10 11:50
Radar Installation
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 66208 Accepted: 14832
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
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
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 21 2-3 12 11 20 20 0
Sample Output
Case 1: 2Case 2: 1
Source
Beijing 2002
和以前做的一道一样Orz
ACcode:
#pragma warning(disable:4786)//使命名长度不受限制#pragma comment(linker, "/STACK:102400000,102400000")//手工开栈#include <map>#include <set>#include <queue>#include <cmath>#include <stack>#include <cctype>#include <cstdio>#include <cstring>#include <stdlib.h>#include <iostream>#include <algorithm>#define rd(x) scanf("%d",&x)#define rd2(x,y) scanf("%d%d",&x,&y)#define rds(x) scanf("%s",x)#define rdc(x) scanf("%c",&x)#define ll long long int#define maxn 100005#define mod 1000000007#define INF 0x3f3f3f3f //int 最大值#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)#define MT(x,i) memset(x,i,sizeof(x))#define PI acos(-1.0)#define E exp(1)using namespace std;struct me{ double f,s;}my[1111];bool comp(me a,me b){ return a.s<b.s;}int main(){ int n,r,i;double x,y; int ccc=1; while(rd2(n,r)!=EOF&&n&&r){ bool flag=false; for(i=0;i<n;++i){ cin>>x>>y; if(y>r) flag=true; my[i].f=x-sqrt(r*r-y*y); my[i].s=x+sqrt(r*r-y*y); } sort(my,my+n,comp); int cns=1; double tt=my[0].s; for(i=0;i<n;++i){ if(tt<my[i].f){ cns++; tt=my[i].s; } } printf("Case %d: ",ccc++); printf(flag?"-1\n":"%d\n",cns); } return 0;}/*3 21 2-3 12 11 20 20 0*/
0 0
- POJ 1328 Radar Installation(贪心)
- POJ 1328 Radar Installation 贪心
- POJ 1328 Radar Installation 贪心
- POJ 1328 贪心 Radar Installation
- POJ 1328 Radar Installation 贪心
- POJ | 1328 Radar Installation | 贪心
- POJ 1328 Radar Installation 贪心
- 贪心-poj-1328-Radar Installation
- POJ 1328 Radar Installation (贪心)
- POJ 1328 Radar Installation 贪心
- POJ 1328 Radar Installation 贪心
- POJ 1328、Radar Installation 贪心
- poj 1328 Radar Installation(贪心)
- POJ 1328 Radar Installation 贪心
- POJ 1328 Radar Installation 贪心
- POJ 1328 Radar Installation 贪心
- Poj 1328 Radar Installation 贪心
- POJ--1328:Radar Installation (贪心)
- WM_CREATE ,WM_NCCREATE,WM_DESTROY,WM_NCDESTROY详解
- android 打包成apk时报错,但是clean后没有错误的解决方法
- java 通过实现Runnable接口实现多线程
- github linux 用法
- js中自定义回调函数
- POJ 1328 Radar Installation 贪心
- 获取iOS设备的唯一标识
- C/C++ IDE之C-Free(配置GCC、Visual C++、Borland C++编译器)
- xml:中无法找到 标签元素
- js中运算符&& 和 || 的使用
- 把《C++Primer》读薄
- socket异步编程--libevent的使用
- Guaranteeing Message Processing(storm 消息处理保证机制)
- Xib文件使用