Title Address: http://poj.org/problem?id=1064
There are n ropes, their lengths are AI, and if you cut a rope of the same length of k from them, how long will each of these k ropes last?
The length of the two-point rope, then verify. Complexity O (NLOGM)
1#include <cstdio>2#include <iostream>3#include <string.h>4#include <algorithm>5#include <math.h>6#include <stdbool.h>7#include <time.h>8#include <stdlib.h>9#include <map>Ten#include <stack> One#include <queue> A#include <vector> - using namespacestd; - #defineCLR (x, y) memset (x,y,sizeof (×)) the #defineSQR (x) ((x) * (x)) - #defineRep (i,a,b) for (int i= (a); i<= (b); i++) - #defineLL Long Long - #defineINF 0x3f3f3f3f + #defineA First - #defineB Second + Const intn=10000+131; A intn,k; at DoubleA[n]; - - BOOLCheckDoublelen) - { - intnum=0; - for(intI=0; i<n;i++) { innum+= (int) (a[i]/len); - } to returnnum>=K; + } - the * voidSolve () $ {Panax Notoginseng Doublelb=0, ub=INF; - thescanf"%d%d",&n,&k); + for(intI=0; i<n;i++) { Ascanf"%LF",&a[i]); the } + - for(intI=0;i< -; i++) { $ DoubleMid= (LB+UB)/2; $ if(check (mid)) { -lb=mid; -}Else { theub=mid; - }Wuyi } theprintf"%.2f\n", Floor (ub* -)/ -); - } Wu - intMain () About { $ solve (); - - return 0; -}
[POJ] 1064 Cable Master (two-point search)