結果

問題 No.355 数当てゲーム(2)
ユーザー krotonkroton
提出日時 2015-07-25 18:31:46
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,173 bytes
コンパイル時間 753 ms
コンパイル使用メモリ 67,416 KB
実行使用メモリ 25,324 KB
平均クエリ数 5.23
最終ジャッジ日時 2024-07-16 20:52:19
合計ジャッジ時間 4,493 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 52
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <tuple>
using namespace std;

pair<int, int> judge(const string& ans, const string& challenge){
	int h = 0, b = 0;
	for(int i=0;i<4;i++){
		if(challenge[i] == ans[i]){
			++h;
		} else if(ans.find(challenge[i]) != string::npos){
			++b;
		}
	}
	return make_pair(h, b);
}

pair<int, int> ask(const string& S){
	cout << S[0] << " " << S[1] << " " << S[2] << " " << S[3] << endl;
	int h, b;
	cin >> h >> b;
	return make_pair(h, b);
}

const pair<int, int> last = make_pair(4, 0);

int main(){
	vector<string> cand;
	for(char a='0';a<='9';a++){
		for(char b='0';b<='9';b++)if(b != a){
			for(char c='0';c<='9';c++)if(c != a && c != b){
				for(char d='0';d<='9';d++)if(d != a && d != b && d != c){
					string num = "";
					num += a;
					num += b;
					num += c;
					num += d;
					cand.push_back(num);
				}
			}
		}
	}

	int size = cand.size();
	for(;;){
		int r = rand() % size;
		string challenge = cand[r];

		auto res = ask(challenge);
		if(res == last){
			break;
		}

		int j = 0;
		for(int i=0;i<size;i++){
			if(judge(cand[i], challenge) == res){
				cand[j] = cand[i];
				++j;
			}
		}

		size = j;
	}
	return 0;
}
0