結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
aparachia14
|
| 提出日時 | 2016-01-13 23:49:15 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 140 ms / 5,000 ms |
| コード長 | 1,806 bytes |
| コンパイル時間 | 3,703 ms |
| コンパイル使用メモリ | 75,636 KB |
| 実行使用メモリ | 52,416 KB |
| 最終ジャッジ日時 | 2024-11-18 08:04:17 |
| 合計ジャッジ時間 | 7,631 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
ソースコード
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
//No.5数字のブロック
public class NumberBlock {
public static void main(String[] args) throws IOException {
// TODO 自動生成されたメソッド・スタブ
//大きな箱の幅
int widthOfBox;
//ブロックの数
int numberOfBlock;
//各ブロックの幅
ArrayList<Integer> widthOfBlock = new ArrayList<Integer>();
//入力値の取得
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
widthOfBox = Integer.parseInt(in.readLine());
numberOfBlock = Integer.parseInt(in.readLine());
String[] temp = in.readLine().split(" ");
//tempをバラし、int型に直しwidthOfBoxに格納する。
for(String width : temp){
widthOfBlock.add(Integer.parseInt(width));
}
//ArrayListから最小値を求め、その値をwidthOfBoxから減算し、その後ArrayListからその値を除外する。
//この処理をwidthOfBoxの値が0以下になるまで繰り返す。
int min;//最小値格納変数
int counter; //カウンタ
int counter2 = 0;//第二カウンタ
int index = 0;//削除対象要素番号格納変数
int capacity = widthOfBox;
while(true){
min = widthOfBox;
counter = 0;
//配列から最小値を求める。
for(int width2 : widthOfBlock){
if(min > width2){//width2の方がminより値が小さければminに格納
min = width2;
index = counter;//削除対象の要素番号を記憶
}else{
}
counter++;
}
if(capacity - min >= 0){
capacity = capacity - min;
counter2++;
}else{
break;
}
widthOfBlock.remove(index);//ArrayListから削除
}
System.out.println(counter2);
}
}
aparachia14