QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#291797#7179. Fischer's Chess Guessing GameOAleksaWA 9ms3716kbC++141.8kb2023-12-27 07:47:022023-12-27 07:47:03

Judging History

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

  • [2023-12-27 07:47:03]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:3716kb
  • [2023-12-27 07:47:02]
  • 提交

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;
};
vector<pair<string, int>> pr;
int g;
void resi(string ans) {
	cout << ans << endl;
	int r;
	cin >> r;
	g++;
	if (r == 8 || g > 6)
		return;
	pr.push_back({ans, r});
	for (auto x : perm) {
		int ok = 1;
		for (auto u : pr) 
			ok &= (diff(u.f, x) == u.s);
		if (ok)
			ans = x;
	}
	resi(ans);
}
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()));
  	while (true) {
  		string s;
  		cin >> s;
  		g = 0;
  		if (s == "GAME") {
  			cin >> s;
  			resi(perm[0]);
  			pr.clear();
  		}
  		else
  			break;
  	}
  }
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 7ms
memory: 3664kb

input:

GAME 1
2
2
3
2
8
END

output:

QNNBBRKR
RBBNNQKR
RBNQBKRN
RNKNBBRQ
RKRBBQNN

result:

ok (c) correct after 1 tests, max moves 5 (1 test case)

Test #2:

score: -100
Wrong Answer
time: 9ms
memory: 3716kb

input:

GAME 1
2
2
3
2
8
GAME 2
2
1
1
5
8
GAME 3
2
1
2
3
8
GAME 4
1
1
3
4
8
GAME 5
1
2
2
3
1
8
GAME 6
1
2
4
2
2
8
GAME 7
1
1
3
1
8
GAME 8
1
3
2
3
2
2

output:

QNNBBRKR
RBBNNQKR
RBNQBKRN
RNKNBBRQ
RKRBBQNN
QNNBBRKR
RBBNNQKR
RNNKRBBQ
RQKBBNRN
RKRBBNQN
QNNBBRKR
RBBNNQKR
RNNKRBBQ
RNKRBNQB
RKRBBNNQ
QNNBBRKR
RBBNNKQR
RNQKRBBN
RNKRQNBB
RKRBQNBN
QNNBBRKR
RBBNNKQR
RBNKRNBQ
RBKRBQNN
RQKNBNRB
RKRBNQBN
QNNBBRKR
RBBNNKQR
RBNKRNBQ
RBQKBNRN
RNBKRBNQ
RKRBNNBQ
QNNBBRKR
RBB...

result:

wrong answer (i) too many guesses in game 8, pos =