poj 1328 Radar Installation_贪心

翻出一年多前的代码看,发现以前的代码风格很糟糕

题意:给你n个点 m为圆的半径,问需要多少个圆能把全部点圈到

#include <iostream>
 #include <algorithm>
 #include <cmath>
 using namespace std;
 struct ss{
     double x,y;
 }a[1005];
 int cmp(ss x,ss y)
 {
     if(x.x==y.x)return x.y<y.y;
     else return x.x<y.x;
 }
 int main()
 {
     int n,i,sum,k,flag;
     double x,y,m;
     double tt,ww;
     k=0;
     while (cin>>n>>m)
     {    
         if(n==0&&m==0.0)break;
         k++;
         flag=1;
         sum=0;
         if(m<0)flag=0;
         for (i=0;i<n;i++)
         {
             cin>>x>>y;
             if(y>m)flag=0;
             if(y<0)flag=0;
             tt=sqrt(m*m-y*y);
             a[i].x=x*1.0-tt;
             a[i].y=x*1.0+tt;
         }
         if(flag==0)
         {cout<<"Case "<<k<<": "<<"-1"<<endl;continue;}
         sort(a,a+n,cmp);
            sum=1;
         ww=a[0].y;
         for (i=1;i<n;i++)
         {
             if(a[i].x>ww){
                 sum++;
                 ww=a[i].y;
             }
             else if(a[i].y<ww){
                 ww=a[i].y;
             }
         }
         cout<<"Case "<<k<<": "<<sum<<endl;    
     }
     return 0;
 }


你可能感兴趣的:(Install)