AOJ 0033
・問題リンク Ball
・コメント
久しぶりのプログラミング・・。問題文をそのまま実装して終わりました。
・ソース
import java.util.Scanner; public class P0033 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i = 0; i < n; i++) {// データ数回実行 int[] ary = new int[12]; for (int j = 0; j < 10; j++) {// 要素記憶 ary[j] = sc.nextInt(); } int tempb = 0, tempc = 0;// C,B boolean flag = true; for (int j = 0; j < 10; j++) { if (tempb == 0) { tempb = ary[j];// 最初はBに入れておく } else {// 最初じゃなかったら if (tempb > ary[j]) {// Bに入れられない時(Bの頭の方が代入要素より大きい場合) if (tempc > ary[j]) {// B,Cともに代入要素より大きい場合 System.out.println("NO"); flag = false; break; } else {// Cには入れられる場合 tempc = ary[j]; } } else {// Bに入れられる時 if (tempc > ary[j]) {// Cに入れられない時 tempb = ary[j]; } else {// B,Cともに入れられる時 if ((ary[j] - tempb) < (ary[j] - tempc)) {// より差の小さい方に入れる tempb = ary[j]; } else { tempc = ary[j]; } } } } } if (flag) { System.out.println("YES"); } } } }