Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求大神改之,数据都过。。。。。。。。就是wa,附代码,贪心做的

Posted by 799098386 at 2012-12-13 01:29:44 on Problem 1328
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
struct sb
{
    double s,e;
}q[10001];
int cmp(const void *a,const void *b)
{
    return (*(sb *)a).s>(*(sb *)b).s?1:-1;
}
int main()
{
    int ss=0,sss;
    int n;
    int i,j,k=0;
    double d,la,lb;
    double g,h;
    int sum;
    double sa,sc;
    while(scanf("%d %lf",&n,&d)!=EOF)
    {
        k++;
        ss=0;
        if(n==0&&d==0.0)break;
        else if(n==1)
        {
            scanf("%lf %lf",&la,&lb);
            printf("Case %d: 1\n",k);
       }
       
        else 
            {
                for(i=0;i<n;i++)
                 {
                    scanf("%lf%lf",&g,&h);
                     if((abs(h)-d)>0) ss=1;
                    q[i].s=g*1.0-(sqrt(1.0*d*d-1.0*h*h));
                    q[i].e=g*1.0+(sqrt(1.0*d*d-1.0*h*h));
                 }     
            if(d<0||ss)
            { 
              printf("Case %d: -1\n",k);
        
            } 
            else{
                qsort(q,n,sizeof(q[0]),cmp);       
                sum=1;
                sc=q[0].e;
                for(j=1;j<n;j++)
                  {                  
                     if(sc<q[j].s)
                     {  sum++;                       
                       sc=q[j].e;
                                      
                     }                       
                     else if(sc>q[j].e)
                     {
                      sc=q[j].e;                      
                     }
                   }                          
           printf("Case %d: %d\n",k,sum);
          } ss=0;
        }
    }
    return 0;
} 


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator