这一题我提交了不下10遍,我的ac率!
错误最后发现在case 后面的情况数下!没有仔细比较结果啊!
错误最后发现在case 后面的情况数下!没有仔细比较结果啊!
/*贪心算法*/
#include <iostream>
//#include <fstream>
#include <algorithm>
#include <math.h>
#define MAX 1010
using namespace std;
typedef struct _point
{
int x;
int y;
}point;
typedef struct _bound
{
double left;
double right;
}bound;
void swap(bound &a,bound &b)
{
bound temp=a;
a=b;
b=temp;
}
//fstream fin;
int main()
{
//fin.open("1328.txt",ios::in);
int n,d;
int count=1; //case
while(cin>>n>>d)
{
//cout<<n<<endl;
if(n==0&&d==0)
break;
point *p=new point[n];
bound *b=new bound[n];
for(int i=0;i<n;i++)
cin>>p[i].x>>p[i].y;
bool flag=true;
for(int i=0;i<n;i++)
if(d<abs(p[i].y))
{
cout<<"Case "<<count++<<": -1"<<endl;
flag=false;
break;
}
//计算一个顶点的左右界
if(flag){
for(int i=0;i<n;i++)
{
b[i].left=p[i].x*1.000-sqrt(d*d*1.00-p[i].y*p[i].y*1.0000);
b[i].right=p[i].x*1.000+sqrt(d*d*1.00-p[i].y*p[i].y*1.0000);
}
for(int i=0;i<n;i++)
{
int j=i;
while(b[j].left<b[j-1].left&&j>0)
{
swap(b[j],b[j-1]);
j--;
}
}
int num=1; //记录雷达的个数
double temp=b[0].right;
for(int i=0;i<n-1;i++)
{
if(b[i+1].left>temp)
{
temp=b[i+1].right;
num++;
}
else if(b[i+1].right<temp)
temp=b[i+1].right;
}
cout<<"Case "<<count++<<": "<<num<<endl;
}
delete []p;
delete []b;
}
system("pause");
return 0;
}