Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

java快把自己玩死了都解不出来

Posted by upstar at 2017-03-24 22:02:25 on Problem 1064
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator