結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー youthfuldays072youthfuldays072
提出日時 2018-06-16 18:05:00
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,061 bytes
コンパイル時間 2,188 ms
コンパイル使用メモリ 73,616 KB
実行使用メモリ 66,912 KB
最終ジャッジ日時 2023-09-13 06:10:10
合計ジャッジ時間 23,914 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 894 ms
64,744 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 834 ms
64,500 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 870 ms
65,000 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 812 ms
64,936 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 863 ms
64,468 KB
testcase_16 AC 885 ms
64,752 KB
testcase_17 AC 807 ms
64,696 KB
testcase_18 AC 808 ms
64,868 KB
testcase_19 AC 884 ms
64,464 KB
testcase_20 AC 871 ms
64,412 KB
testcase_21 AC 885 ms
63,196 KB
testcase_22 AC 792 ms
64,500 KB
testcase_23 AC 795 ms
62,732 KB
testcase_24 AC 120 ms
55,764 KB
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 184 ms
56,204 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main{

	boolean[] isprime=new boolean[20010];

	public static void main(String[] args) {
		Main main=new Main();
		main.run();
	}

	void run() {


		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();

		int[] L=new int[N];

		int maxlength=-1;
		for(int i=0;i<N;i++) {

			int buf=sc.nextInt();
			L[i]=buf;

			if(maxlength<buf) {
				maxlength=buf;
			}
		}

		int K=sc.nextInt();

		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 int calc(double cutwidth,int[] L) {

		int count=0;

		for(int i=0;i<L.length;i++) {
			count+=(int)L[i]/cutwidth;
		}


		return count;
	}

	//ある幅でK本以上とれるかどうか判定する関数。
	public static boolean judge(double cutwidth,int[] L,int K) {

		if(calc(cutwidth,L)>=K) {
			return true;
		}else {
			return false;
		}

	}




}

0