AtCoder Beginner Contest 005をやった。
C問題、、、できるかな。。。再起処理だと思うんだけど。。。
普通にループさせました。ただ一番最初からループさせたらパンクしそうな気がしたので、ちょっと工夫しました。
A
整数値を求めて、割り算する問題
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
// Your code here!
Scanner scan = new Scanner(System.in);
ArrayList<String> list = new ArrayList<String>();
list.add(scan.nextLine());
System.out.println(Integer.parseInt(list.get(0).split(" ")[1]) / Integer.parseInt(list.get(0).split(" ")[0]));
}
}
B
一番小さい(温かいたこやき)番号を求めよう。
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
// Your code here!
Scanner scan = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(scan.nextInt());
for(int i = 1; i <= list.get(0); i++){
list.add(scan.nextInt());
}
int min = list.get(1);
for(int i = 1; i <= list.get(0); i++){
if(min > list.get(i)){
min = list.get(i);
}
}
System.out.println(min);
}
}
C
たこやきを売れるかが勝負なのです。
提示された条件でお客さんにたこ焼きが売れるなら、たこ焼き用の配列の要素の次の番号を見るようにします。
※別言語のソースなど見ていると、popなどしても近い回答になりそうです
C問題途中のコメントアウトは// -----写真参照で、テストケースが洩れていた時に書いていなかったソースです。
漏れていただろうテストケースはソースの後ろに書きます。
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
// Your code here!
Scanner scan = new Scanner(System.in);
ArrayList<String> list = new ArrayList<String>();
while (scan.hasNextLine()) {
list.add(scan.nextLine());
}
if(Integer.parseInt(list.get(1)) < Integer.parseInt(list.get(3))){
System.out.println("no");
} else {
int[] An = new int[Integer.parseInt(list.get(1))];
for(int i = 0; i < Integer.parseInt(list.get(1)); i++){
An[i] = Integer.parseInt(list.get(2).split(" ")[i]);
}
// たこやきが売れるかのフラグ
boolean flg = true;
int y = 0;
for(int i = 0; i < Integer.parseInt(list.get(3)); i++){
for(int j = y; j < An.length; j++){
if(
Integer.parseInt(list.get(4).split(" ")[i]) - Integer.parseInt(list.get(0)) <= An[j] &&
An[j] <= Integer.parseInt(list.get(4).split(" ")[i])
){
y = j + 1;
flg = true;
break;
} else {
flg = false;
}
}
// -------------------------
if(flg == false){
break;
}
// -------------------------
}
if(flg == true){
System.out.println("yes");
} else if(flg == false){
System.out.println("no");
}
}
}
}
2 5 5 5 5 6 7 5 3 3 3 3 8
上記で示した行がないと、一番最後の判定で 8 - 2 <= 7 && 7 <= 8がtrueになってしまうのでした、、
D問題ムズイ