QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#291813#7179. Fischer's Chess Guessing GameOAleksaCompile Error//C++142.2kb2023-12-27 08:47:232023-12-27 08:47:23

Judging History

你现在查看的是最新测评结果

  • [2023-12-27 08:47:23]
  • 评测
  • [2023-12-27 08:47:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define int long long
vector<char> sv = {'K', 'Q', 'N', 'N', 'B', 'B', 'R', 'R'};
vector<string> perm;
int good(vector<char> ord) {
	int x = -1, y = -1, z = -1, b = -1, a = -1;
	for (int i = 0;i < 8;i++) {
		if (ord[i] == 'K')
			z = i;
		else if (ord[i] == 'B') {
			if (x == -1)
				x = i;
			else
				y = i;
		}
		else if (ord[i] == 'R') {
			if (a == -1)
				a = i;
			else
				b = i;
		}
	}
	return z < b && z > a && x % 2 != y % 2;
};
int diff(string a, string b) {
	int r = 0;
	for (int i = 0;i < 8;i++)
		r += (a[i] == b[i]);
	return r;
};
void resi(string ans, int g) {
	cout << ans << endl;
	int r;
	cin >> r;
	if (r == 8 || g > 6)
		return;
	vector<string> temp;
	for (auto x : perm) {
		if (diff(ans, x) == r)
			temp.push_back(x);
	}
	int mn = 1e9;
	for (auto u : temp) {
		vector<int> cnt(10);
		int mx = 0;
		for (auto x : perm) 
			mx = max(mx, ++cnt[diff(u, x)]);
		if (mx < mn) {
			mn = mx;
			ans = u;
		}
	}
	resi(ans, g + 1);
}
signed main() {
	ios_base::sync_with_stdio(false);
  cout.tie(nullptr); 
  cin.tie(nullptr);
  //freopen("newbarn.in", "r", stdin);
  //freopen(newbarn.out", "w", stdout);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
  	vector<int> order(8);
  	iota(order.begin(), order.end(), 0);
  	map<string, int> bio;
  	do {
  		vector<char> t;
  		for (int i = 0;i < 8;i++)
  			t.push_back(sv[order[i]]);
  		if (good(t)) {
  			string s;
  			for (auto x : t)
  				s += x;
  			if (bio[s])
  				continue;
  			bio[s] = 1;
  			perm.push_back(s);
  		}
  	} while (next_permutation(order.begin(), order.end()));
  	int mx = 1e9;
  	string ans1;
  	for (int i = 0;i < 960;i++) {
  		vector<int> cnt(10);
  		int l = 0;
  		for (int j = 0;j < 960;j++) {
  			if (i == j)
  				continue;
  			l = max(l, ++cnt[diff(perm[i], perm[j])]);
  		}
  		if (l < mx) {
  			ans1 = perm[i];
  			mx = l;
  		}
  	}
  	while (true) {
  		string s;
  		cin >> s;
  		if (s == "GAME") {
  			cin >> s;
  			ans = ans1;
  			resi(ans, 0);
  		}
  		else
  			break;
  	}
  }
  return 0;
}

詳細信息

answer.code: In function ‘int main()’:
answer.code:104:25: error: ‘ans’ was not declared in this scope; did you mean ‘ans1’?
  104 |                         ans = ans1;
      |                         ^~~
      |                         ans1