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

Re:这题有什么trick吗?不是先排序在尽量多的控制连续几个点吗?

Posted by lonelydancer at 2008-07-02 18:41:38 on Problem 1328
In Reply To:这题有什么trick吗?不是先排序在尽量多的控制连续几个点吗? Posted by:TN at 2005-01-08 14:12:11
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define EPS 1e-6
struct point
{
    double l;
    double r;
};
typedef struct point point;
int cmp(const void * a,const void * b);

int compare(double a,double b);
int main()
{
    int n,d;

    int tag;
    point p[1001];
    int count,t=1,i,j,x,y;
    double a;
    while (scanf("%d %d",&n,&d)==2&&(n!=0||d!=0))
    {  tag=1;
       if(n==0)
       tag=0;
        for (i=0;i<n;i++)
          {  scanf("%d %d",&x,&y);
          if(d<=0)
           tag=0;
            if(d*d<y*y)
             tag=0;
            else
            {a=sqrt(d*d-y*y);
             p[i].l=x-a;
             p[i].r=x+a;
            }
          }
        qsort(p,n,sizeof(point),cmp);
        count=1;
        i=0;
        while(i<n)
        { for(j=i+1;j<n;j++)
            if(compare(p[i].l,p[j].r)==1)
            {count++;
              i=j;
              if(j==n-1)
              i=n;
              break;
            }
          if(j==n)
          break;
        }
          if(tag)
          printf("Case %d: %d\n",t++,count);
          else
          printf("Case %d: -1\n",t++);

    }
    return 0;
}
int cmp(const void * a,const void * b)
{
    return (*(point*)a).r<(*(point*)b).r? 1: -1;
}

int compare(double a,double b)
{ if (fabs(a-b)<EPS)
     return 0;
else if (a-b>0)
return 1;
return -1;
}

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