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 |
注意平方爆整形。事先转换成doulbe吧#include <iostream> #include <stdio.h> #include <cmath> #include <algorithm> using namespace std; int N, d; struct intv{ double s, e; }intvs[1005]; bool compare(const intv &i1, const intv &i2){ return i1.e < i2.e; } int main() { int cnt = 0; while(1){ scanf("%d%d", &N, &d); if(N==0 && d==0) return 0; cnt++; printf("Case %d: ", cnt); bool rrky = 1; if(d < 0) rrky = 0; for(int i = 0; i < N; i++){ int x, y; scanf("%d%d", &x, &y); if(abs(y+0.0) > d) rrky = 0; if(rrky){ double sqt = sqrt(0.0+d*1.0*d-y*1.0*y); intvs[i].s = x-sqt, intvs[i].e = x+sqt; } } if(!rrky){ printf("-1\n"); continue; } sort(intvs, intvs+N, compare); int num = 0; double curPos = -1e300; for(int i = 0; i < N; i++){ if(curPos < intvs[i].s){ num++; curPos = intvs[i].e; } } printf("%d\n", num); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator