結果
| 問題 |
No.67 よくある棒を切る問題 (1)
|
| コンテスト | |
| ユーザー |
youthfuldays072
|
| 提出日時 | 2018-06-16 18:11:07 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,091 bytes |
| コンパイル時間 | 3,559 ms |
| コンパイル使用メモリ | 85,616 KB |
| 実行使用メモリ | 69,948 KB |
| 最終ジャッジ日時 | 2025-03-03 11:17:31 |
| 合計ジャッジ時間 | 52,651 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 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();
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;
}
}
}
youthfuldays072