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 |
Re:这题有什么trick吗?不是先排序在尽量多的控制连续几个点吗?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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator