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 |
1A贴个代码#include <iostream> #include <cstring> #include <stdio.h> #include <algorithm> #include <cmath> #include <map> #include <vector> using namespace std; int n; double d; struct Node{ double l,r; }node[1010]; bool cmp(const Node& x, const Node& y) { if(fabs(x.r - y.r) < 1e-5) { return x.l < y.l; } return x.r < y.r; } int main() { int C = 1; while(scanf("%d%lf",&n,&d),n + d) { double rmax = -0x3f3f3f3f; bool ok = true; for(int i = 0;i < n;i ++) { double x,y; scanf("%lf%lf",&x,&y); if(d < y) { ok = false; continue; } double dx = sqrt(d * d - y * y); node[i].r = x + dx; node[i].l = x - dx; rmax = max(rmax,node[i].r); } if(ok == false) { printf("Case %d: %d\n",C++,-1); continue; } sort(node,node+n,cmp); int ret = 0; int index = 0; double end; do { end = node[index].r; while(index < n && (node[index].l < end || fabs(node[index].l - end) < 1e-5)) { index ++; } ret ++; if(index >= n) { break; } }while(end < rmax || fabs(end-rmax) > 1e-5); printf("Case %d: %d\n",C++,ret); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator