結果
問題 | No.355 数当てゲーム(2) |
ユーザー |
|
提出日時 | 2016-05-04 16:36:17 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 225 ms / 2,000 ms |
コード長 | 1,873 bytes |
コンパイル時間 | 2,129 ms |
コンパイル使用メモリ | 80,160 KB |
実行使用メモリ | 61,192 KB |
平均クエリ数 | 5.50 |
最終ジャッジ日時 | 2024-07-16 23:40:40 |
合計ジャッジ時間 | 15,809 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 52 |
ソースコード
import java.util.ArrayList;import java.util.List;import java.util.Scanner;public class Main {public static Scanner sc = new Scanner(System.in);public static void main(String[] args) {new Main().solve();}public void solve() {List<int[]> candidate = new ArrayList<int[]>();for (int j = 0; j < 10000; j++) {int c1 = j % 10;int c2 = j / 10 % 10;int c3 = j / 100 % 10;int c4 = j / 1000 % 10;if (c1 == c2 || c1 == c3 || c1 == c3 || c1 == c4 || c2 == c3 || c2 == c4 || c3 == c4) {continue;} else {int[] r = new int[4];r[0] = c1;r[1] = c2;r[2] = c3;r[3] = c4;candidate.add(r);}}while (candidate.size() > 1) {int[] c = candidate.get(0);send(c);String input = get();if (input.equals("4 0")) {return;} else {candidate.remove(0);List<Integer> rm = new ArrayList<>();for (int i = 0; i < candidate.size(); i++) {if (isContradiction(candidate.get(i), input, c)) {// System.out.println("remove " + toS(candidate.get(i)));rm.add(i);candidate.remove(i);i--;}}// System.out.println(candidate.size());}}send(candidate.get(0));}private String toS(int[] c) {return (c[0] + " " + c[1] + " " + c[2] + " " + c[3]);}private void send(int[] c) {send(c[0] + " " + c[1] + " " + c[2] + " " + c[3]);}private boolean isContradiction(int[] can, String input, int[] ans) {int m1 = 0;int m2 = 0;for (int i = 0; i < 4; i++) {for (int j = 0; j < 4; j++) {if (ans[i] == can[j]) {m2++;}}}for (int i = 0; i < 4; i++) {if (ans[i] == can[i]) {m1++;m2--;}}return ! input.equals(m1 + " " + m2);}protected void send(String s) {System.out.println(s);System.out.flush();}protected String get() {return sc.nextLine();}}