結果
問題 | No.355 数当てゲーム(2) |
ユーザー |
|
提出日時 | 2016-04-02 20:08:22 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 168 ms / 2,000 ms |
コード長 | 3,062 bytes |
コンパイル時間 | 4,031 ms |
コンパイル使用メモリ | 79,976 KB |
実行使用メモリ | 70,788 KB |
平均クエリ数 | 5.52 |
最終ジャッジ日時 | 2024-07-16 23:28:02 |
合計ジャッジ時間 | 14,174 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 52 |
ソースコード
import java.io.*;import java.util.*;public class Main_yukicoder355 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);Printer pr = new Printer(System.out);Queue<List<Integer>> q = new ArrayDeque<>();for (int i = 0; i < 10; i++) {for (int j = 0; j < 10; j++) {if (i == j) {continue;}for (int k = 0; k < 10; k++) {if (k == i || k == j) {continue;}for (int l = 0; l < 10; l++) {if (l == i || l == j || l == k) {continue;}ArrayList<Integer> tmp = new ArrayList<>();tmp.add(i);tmp.add(j);tmp.add(k);tmp.add(l);q.add(tmp);}}}}while (!q.isEmpty()) {// pr.println(q.size());List<Integer> e = q.remove();send(e, pr);int x = sc.nextInt();int y = sc.nextInt();if (x == 4 && y == 0) {break;}Queue<List<Integer>> qtmp = new ArrayDeque<>();for (List<Integer> ee : q) {if (eq(e, ee, x, y)) {qtmp.add(ee);}}q = qtmp;}pr.close();sc.close();}private static boolean eq(List<Integer> e, List<Integer> ee, int x, int y) {int xtmp = 0;int ytmp = 0;for (int i = 0; i < e.size(); i++) {for (int j = 0; j < e.size(); j++) {if (e.get(i) == ee.get(j)) {if (i == j) {xtmp++;} else {ytmp++;}}}}if (x == xtmp && y == ytmp) {return true;} else {return false;}}private static void send(List<Integer> num, Printer pr) {pr.printf("%d %d %d %d\n", num.get(0), num.get(1), num.get(2), num.get(3));pr.flush();return;}@SuppressWarnings("unused")private static class Scanner {BufferedReader br;Iterator<String> it;Scanner (InputStream in) {br = new BufferedReader(new InputStreamReader(in));}String next() throws RuntimeException {try {if (it == null || !it.hasNext()) {it = Arrays.asList(br.readLine().split(" ")).iterator();}return it.next();} catch (IOException e) {throw new IllegalStateException();}}int nextInt() throws RuntimeException {return Integer.parseInt(next());}long nextLong() throws RuntimeException {return Long.parseLong(next());}float nextFloat() throws RuntimeException {return Float.parseFloat(next());}double nextDouble() throws RuntimeException {return Double.parseDouble(next());}void close() {try {br.close();} catch (IOException e) {// throw new IllegalStateException();}}}private static class Printer extends PrintWriter {Printer(PrintStream out) {super(out);}}}