結果
問題 |
No.67 よくある棒を切る問題 (1)
|
ユーザー |
![]() |
提出日時 | 2018-06-16 18:05:00 |
言語 | Java (openjdk 23) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,061 bytes |
コンパイル時間 | 4,350 ms |
コンパイル使用メモリ | 80,528 KB |
実行使用メモリ | 70,056 KB |
最終ジャッジ日時 | 2025-03-03 11:16:39 |
合計ジャッジ時間 | 26,532 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 RE * 16 |
ソースコード
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; } } }