# POJ1064二分

110人阅读 评论(0)

n根线，现在要把这n根线切割成k根等长（设长为len）的线，问能切得的最长的len为多少，

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class Main {
public static void main(String[] args){
new POJ1064().solve()  ;
}
}

class POJ1064{

PrintWriter out = new PrintWriter(System.out) ;
final int N = 10008 ;
double[] x = new double[N] ;
int n , k ;
boolean judge(double l){
int cnt = 0 ;
for(int i = 0 ; i < n ; i++){
cnt += (int)(x[i] / l) ;
}
return cnt >= k ;
}

void solve(){
n = in.nextInt() ;
k = in.nextInt() ;
double left = 0.0 , right = 0.0 , mid , res = -1 ;
for(int i = 0 ; i < n ; i++){
x[i] = in.nextDouble() ;
right = Math.max(right , x[i]) ;
}
for(int i = 0 ; i < 100 ; i++){
mid = (left + right) / 2 ;
if(judge(mid)) res = left = mid ;
else right = mid ;

}
out.printf("%.2f" , Math.floor(res*100)/100) ;
out.println();
out.flush() ;
}
}

public StringTokenizer tokenizer;

tokenizer = new StringTokenizer("");
}

private void eat(String s) {
tokenizer = new StringTokenizer(s);
}

public String nextLine() {
try {
} catch (Exception e) {
return null;
}
}

public boolean hasNext() {
while (!tokenizer.hasMoreTokens()) {
String s = nextLine();
if (s == null)
return false;
eat(s);
}
return true;
}

public String next() {
hasNext();
}

public int nextInt() {
return Integer.parseInt(next());
}

public long nextLong() {
return Long.parseLong(next());
}

public double nextDouble() {
return Double.parseDouble(next());
}

public BigInteger nextBigInteger() {
return new BigInteger(next());
}

}



0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：224389次
• 积分：9766
• 等级：
• 排名：第1867名
• 原创：680篇
• 转载：0篇
• 译文：0篇
• 评论：55条
文章分类
阅读排行
最新评论