| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
AC 用C++,G++不小心就会超时,贴代码#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
struct point
{
double left,right;
};
point p[1005];
bool cmp(point a,point b)
{
if(a.left!=b.left)
return a.left<b.left;
return a.right<b.right;
}
int main()
{
int n,i,flag,t=1,sum;
double r,x,y,last;
while(cin>>n>>r)
{
if(n==0&&r==0) break;
flag=0;
for(i=1;i<=n;i++)
{
cin>>x>>y;
p[i].left=x-sqrt(r*r-y*y);
p[i].right=x+sqrt(r*r-y*y);
if(y>r) flag=1;
}
cout<<"Case "<<t++<<": ";
if(flag)
{
cout<<"-1"<<endl;
continue;
}
sort(p+1,p+n+1,cmp);
sum=1;
last=p[1].right;
for(i=2;i<=n;i++)
{
if(last>p[i].right)
last=p[i].right;
else if(last<p[i].left)
{
sum++;
last=p[i].right;
}
}
cout<<sum<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator