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 |
竟然把中间值当做int型!!!wrong了好久啊 ,贴下代码吧#include"stdio.h" #include"string.h" #include"math.h" #include"iostream" #include"algorithm" using namespace std; #define N 1005 struct node { double l,r; }p[N]; double x[N],y[N]; bool cmp(node a,node b) { return a.l<b.l; } int main() { int i,n,d,cnt=1,flag; while(scanf("%d%d",&n,&d),n||d) { flag=0; for(i=0;i<n;i++) { scanf("%lf%lf",&x[i],&y[i]); if(flag) continue; if(d<y[i]) flag=1; double t=sqrt(d*d-y[i]*y[i]); p[i].l=x[i]-t; p[i].r=x[i]+t; } printf("Case %d: ",cnt++); if(flag) { printf("-1\n"); continue; } sort(p,p+n,cmp); int t=1; double rr; //好郁闷啊 rr=p[0].r; for(i=1;i<n;i++) { if(p[i].l>rr) { rr=p[i].r; t++; } if(p[i].r<rr) { rr=p[i].r; } } printf("%d\n",t); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator