結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー youthfuldays072youthfuldays072
提出日時 2018-06-16 18:11:07
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,091 bytes
コンパイル時間 2,066 ms
コンパイル使用メモリ 73,968 KB
実行使用メモリ 69,536 KB
最終ジャッジ日時 2023-09-13 06:15:09
合計ジャッジ時間 49,637 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,943 ms
69,236 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1,762 ms
69,344 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1,890 ms
68,352 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1,765 ms
68,248 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1,783 ms
68,944 KB
testcase_16 AC 1,581 ms
68,372 KB
testcase_17 AC 1,846 ms
68,556 KB
testcase_18 AC 1,856 ms
68,860 KB
testcase_19 AC 1,775 ms
68,700 KB
testcase_20 AC 1,907 ms
68,868 KB
testcase_21 AC 1,930 ms
68,680 KB
testcase_22 AC 1,561 ms
68,500 KB
testcase_23 AC 1,618 ms
68,988 KB
testcase_24 AC 135 ms
55,596 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 268 ms
62,316 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

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();

		double[] L=new double[N];

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

			double buf=sc.nextDouble();
			L[i]=buf;

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

		double K=sc.nextDouble();

		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,double[] 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,double[] L,double K) {

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

	}




}

0