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 |
我擦,死活过不了,跪求大牛帮我看一下#include<stdio.h> #include<math.h> #include<stdlib.h> struct node { double l; double r; }; int cmp(const void * a, const void * b) { struct node *aa=(node *)a; struct node *bb=(node *)b; return(((aa->l)>(bb->l))?1:-1); } int main() { struct node s[1000],ss[1000]; int num,i,j,k,sum,n,q,aa,temp; double dis,x,y; aa=1; while(scanf("%d%lf",&num,&dis)&&(num!=0||(int)dis!=0)) { q=0; sum=0; for(i=0;i<num;i++) { scanf("%lf%lf",&x,&y); if(y>dis) q=1; s[i].l=x-sqrt(dis*dis-y*y); s[i].r=x+sqrt(dis*dis-y*y);//计算区间 } if(q==1) { printf("Case %d: -1\n",aa); aa++; continue; } qsort(s,num,sizeof(s[0]),cmp);//把区间排序 ss[0].l=s[0].l; ss[0].r=s[0].r; for(i=1,j=0;i<num;i++)//合并区间 { if(ss[j].r>s[i].l) { ss[j].l=s[i].l; } else if(ss[j].r>s[i].r) { ss[j].r=s[i].r; } else { j++; ss[j].l=s[i].l; ss[j].r=s[i].r; } } printf("Case %d: %d\n",aa,j+1); aa++; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator