結果
| 問題 | No.67 よくある棒を切る問題 (1) | 
| コンテスト | |
| ユーザー |  youthfuldays072 | 
| 提出日時 | 2018-06-16 18:19:08 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,040 ms / 5,000 ms | 
| コード長 | 1,033 bytes | 
| コンパイル時間 | 2,822 ms | 
| コンパイル使用メモリ | 86,120 KB | 
| 実行使用メモリ | 72,492 KB | 
| 最終ジャッジ日時 | 2025-03-03 11:18:01 | 
| 合計ジャッジ時間 | 29,177 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 30 | 
ソースコード
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Main main=new Main();
		main.run();
	}
	void run() {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		long[] L=new long[N];
		long maxlength=-1;
		for(int i=0;i<N;i++) {
			long buf=sc.nextLong();
			L[i]=buf;
			if(maxlength<buf) {
				maxlength=buf;
			}
		}
		Long K=sc.nextLong();
		double l=0.0;
		double u=maxlength+1;
		double mid=0.0;
		for(int i=0;i<100;i++) {
			mid=(l+u)/2.0;
			if(judge(mid,L,K)) {
				l=mid;
			}else {
				u=mid;
			}
		}
		System.out.println(mid);
	}
	//ある幅で何本とれるか返す関数
	public static long calc(double cutwidth,long[] L) {
		long count=0;
		for(int i=0;i<L.length;i++) {
			count+=(int)L[i]/cutwidth;
		}
		return count;
	}
	//ある幅でK本以上とれるかどうか判定する関数。
	public static boolean judge(double cutwidth,long[] L,long K) {
		if(calc(cutwidth,L)>=K) {
			return true;
		}else {
			return false;
		}
	}
}
            
            
            
        