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 |
java快把自己玩死了都解不出来import java.util.Arrays; import java.util.Scanner; public class Main { static int n,k; static double l[] = new double[10010]; static double sum; public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()) { n = sc.nextInt(); k = sc.nextInt(); sum = 0; for(int i = 0 ; i < n ; i++ ) { l[i] = sc.nextDouble(); sum += l[i]; } sum = sum/k; double l=0 , r = sum; while(Math.abs(l-r)>0.000000001) { double mid = (l+r)/2; if(f(mid)) l = mid; else r = mid; } System.out.printf("%.2f\n",l-0.005); } } private static boolean f(double s) { int cnt = 0; for(int i = 0 ; i < n ; i++ ) { cnt+=(int)(l[i]/s); } if(cnt >= k) { return true; } return false; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator