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:...我对照着一个ac的代码看了半天系统数据的时候还是wa了。。。救命啊2个钟头了!In Reply To:...我对照着一个ac的代码看了半天系统数据的时候还是wa了。。。救命啊2个钟头了! Posted by:dsfhlha at 2013-09-08 17:02:05 > #include <cmath> > #include <cstdio> > #include <cstdlib> > #include <iostream> //哪里错了!! > > using namespace std; > > const int maxn = 1000; > struct Point > { > double l, r; > int x, y; > } line[maxn]; > int cmp(const void *a, const void *b) > { > return (*(Point*)a).x > (*(Point*)b).x; > } > int main() > { > int n, d; > int t=0; > while(cin >> n >> d && (n!=0 || d!=0)) > { > t++; > int flag=1; > int ans = 0; > for(int i=0; i<n; i++) > { > scanf("%d%d", &line[i].x, &line[i].y); > if(line[i].y>d ||d<0) flag=0; > } > if(flag) > { > qsort(line, n, sizeof(line[0]), cmp); > for(int i=0; i<n; i++) > { > double xx = (double)sqrt((double)d*d-line[i].y*line[i].y); > line[i].l = line[i].x-xx; > line[i].r = line[i].x+xx; > } > double now=line[0].r; > > ans++; > for(int i=1; i<n; i++) > { > // printf("\n ans= %d now = %lf line[i].l=%lf \n", ans, now, line[i].l); > if(now>line[i].r) { now=line[i].r;} > else if(now<line[i].l) > { > ans++; > now=line[i].r; > } > } > } > else ans=-1; > printf("Case %d: %d\n\n", t, ans); > } > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator