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<stdlib.h> #include<math.h> struct position { double raw; double line; }; int main() { struct position *p,t; int n,i,number,range,j,extend,zong,flag2; double h,a[1001],b[1001],d; for(zong=1;;zong++) { scanf("%d%lf",&n,&d); if(n!=0||d!=0) { //printf("%d\n",n); p=(struct position*)malloc(n*sizeof(struct position)); for(i=0;i<n;i++) { scanf("%lf%lf",&p[i].raw,&p[i].line); } for(i=0;i<n-1;i++) { for(j=0;j<n-i-1;j++) { if(p[j].raw>p[j+1].raw) { t=p[j]; p[j]=p[j+1]; p[j+1]=t; } } }//排序完成 flag2=0; for(i=0,number=1;i<n;i++,number++)//number指区间的个数,i是指岛的序号 { h=(d*d-(p[i].line)*(p[i].line)); if(h<0) { flag2=1; break; } //printf("lijuan\n"); if(h==0) { a[number]=b[number]=p[i].raw; } if(h>0) { a[number]=p[i].raw-sqrt(h); b[number]=p[i].raw+sqrt(h); }//确定区间a、b //printf("lijuan\n"); if(number>=2) { int flag=0; for(range=1;range<number;range++) { if(a[number]>=a[range]&&a[number]<=b[range])//a在雷达区间内 { int l=0; for(extend=1;extend<number;extend++) { if(b[number]>=a[extend]&&b[number]<=b[extend])//b在雷达区间内 { l=1; a[range]=a[number]; b[extend]=b[number]; number--; flag=1; break; } } if(l!=1)//b在雷达区间外 { a[range]=a[number]; number--; flag=1; break; } } } if(flag==0)//a在雷达区间外 { if(a[number]>=b[number-1]) { continue; } else { int l=0; for(extend=1;extend<number;extend++) { if(b[number]>=a[extend]&&b[number]<=b[extend])//b在雷达区间内 { l=1; b[extend]=b[number]; number--; break; } } if(l==0)//b在雷达区间外 { number--; } } } } } if(flag2==0) { number--; printf("Case %d: %d\n",zong,number); } else { printf("Case %d: -1\n",zong); } } else { break; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator