Actually, that OJ, I don't know what the name is.
This problem, you will know the answer to two points after reading
And then it becomes a matter of judgment, in fact, to group points
Assuming the answer now is cost, then if the vertical distance of 2 points >2*cost, then these 2 points cannot be divided into one group
/************************************************************************* > File Name:code.cpp > Author: ALex > Mail: [email protected] > Created time:2015 May 01 Friday 18:01 11 seconds *********************************** *************************************/#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <queue>#include <stack>#include <map>#include <bitset>#include <set>#include <vector>using namespace STD;Const DoublePI =ACOs(-1.0);Const intINF =0x3f3f3f3f;Const DoubleEPS =1e-15;typedef Long LongLL;typedefPair <int,int> PLL;structPoint {intx, y;} point[10010];intCMP (point A, point B) {returna.x < b.x;}intMain () {intTscanf("%d", &t); while(t--) {intN, K;scanf("%d%d", &n, &k); for(inti =1; I <= N; ++i) {scanf("%d%d", &point[i].x, &POINT[I].Y); } sort (Point +1, point + N +1, CMP);DoubleL =0, R = (Double) INF, Mid;intUse =0;DoubleAns while(R-l >1e-6) {mid = (L + r)/2; Use =1;intmins = point[1].Y, Maxs = point[1].Y; for(inti =1; I <= N; ++i) {mins = min (mins, point[i].y); MAXS = Max (Maxs, POINT[I].Y);if(Maxs-mins >2* mid) {++use; mins = POINT[I].Y; Maxs = POINT[I].Y; } }if(Use > K) {L = mid; }Else{ans = mid; R = Mid; } }printf("%.1f\n", ans); }return 0;}
ACM-ICPC Live Archive 6505---Metal (two minutes)