区间重叠问题 (贪心)
来源:互联网 发布:剑灵天族枪手捏脸数据 编辑:程序博客网 时间:2024/06/14 08:16
Figure A Sample Input of Radar Installations
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
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.
3 21 2-3 12 11 20 20 0
Case 1: 2Case 2: 1
using namespacestd;
typedef struct points{
double x;
double y;}type;boolcmp(type a,type b){
if (a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
int main(){
type *pt,*xd;
double x1,x2,border;
int i,j,k,n,count=1,r,flag=1,flag1=0;
while (scanf("%d%d",&n,&r))
{
if (n==0&&r==0)
break;
pt=new type[n];
xd=new type[n];
for (i=0;i<n;i++)
{
cin>>pt[i].x>>pt[i].y;
if (pt[i].y>r||r<0||pt[i].y<0)
flag1=1;
}
if (flag1)
{
cout<<"Case"<<" "<<flag<<":"<<" "<<"-1"<<endl;
flag1=0;
flag++;
}
else
{
sort (pt,pt+n,cmp);
for (i=0;i<n;i++)
{
xd[i].x=pt[i].x-sqrt(r*r-pt[i].y*pt[i].y);
xd[i].y=pt[i].x+sqrt(r*r-pt[i].y*pt[i].y); }border=xd[0].y;
for (i=1;i<n;i++)
{
if (border>xd[i].y)
border=xd[i].y;
else
{
if (xd[i].x>border)
{
border=xd[i].y;
count++;
}
}
}
cout<<"Case"<<" "<<flag<<":"<<" "<<count<<endl;
count=1;
flag++;
}
}
return 0;
}
阅读全文
0 0
- 区间重叠问题 (贪心)
- HDU1050-贪心-区间重叠
- 会场安排问题(南阳oj14)(贪心-区间不重叠)
- Moving Tables(杭电1050)(贪心---区间不重叠问题)
- POJ NO.2376 Cleaning Shifts(贪心,区间重叠)
- 51Nod1091 线段的重叠(贪心法+区间相关)
- 线段重叠(活动安排)问题 贪心
- 区间覆盖问题(贪心)
- 区间相交问题(贪心)
- 区间选点问题(贪心)
- 区间覆盖问题(贪心)
- 区间选点问题(贪心)
- 区间选点问题(贪心)
- 区间覆盖问题(贪心)
- 区间覆盖问题(贪心)
- 区间覆盖问题(贪心)
- 区间覆盖问题(贪心)
- 区间调度问题(贪心)
- USACO Section 1.2 Dual Palindromes
- 设计模式
- 使用Python类的 __init__( ) 函数定义成员变量
- matlab生成随机数的rand、randi和randn三种形式
- 第十届河南省省赛- 问题 A: 谍报分析
- 区间重叠问题 (贪心)
- jQuery
- 南阳理工oj P2 括号配对问题
- java -verbose命令
- php登录验证+MD5
- Android hardware accelator
- angularjs路由小案例
- JSON
- LeetCode #136