ZOJ 10th Anniversary Contest - I A Song of Anniversary
#include<stdio.h> #include<math.h> #include<vector> #include<algorithm> using namespace std; inline double sqr(double x) { return x*x; } struct Point { int x,y; int time; bool operator < (const Point & p2) const { return time<p2.time; } double operator ^ (const Point & p2) const { return sqrt(sqr(x-p2.x)+sqr(y-p2.y)); } void read(const char * s) { sscanf(s,"%d,%d,%d,%*d,%*d",&x,&y,&time); } }; vector <Point> vp; int k; bool read() { static bool first=true; if (first) { if (scanf("%*s")==EOF) return false; first=false; } if (scanf("%d",&k)==EOF) return false; vp.clear(); static char s[256]; while (1) { if (scanf("%s",s)==EOF) return true; if (s[0]=='[') return true; Point p; p.read(s); vp.push_back(p); } return true; } vector<double> vd; int main() { freopen("i.in","r",stdin); while (read()) { sort(vp.begin(),vp.end()); vd.clear(); int n=vp.size(); int i; for (i=1;i<n;i++) { vd.push_back(vp[i]^vp[i-1]); } sort(vd.begin(),vd.end()); double ans; if (k==0) ans=0; else ans=vd[n-k]; printf("%.3f\n",ans); } return 0; }