結果
問題 | No.67 よくある棒を切る問題 (1) |
ユーザー | youthfuldays072 |
提出日時 | 2018-06-16 18:19:08 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,165 ms / 5,000 ms |
コード長 | 1,033 bytes |
コンパイル時間 | 2,319 ms |
コンパイル使用メモリ | 77,372 KB |
実行使用メモリ | 73,020 KB |
最終ジャッジ日時 | 2024-11-08 12:45:39 |
合計ジャッジ時間 | 32,314 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
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; } } }