QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#492260#7179. Fischer's Chess Guessing Gameno_RED_no_DEADTL 1ms3892kbC++201.6kb2024-07-26 10:54:472024-07-26 10:54:47

Judging History

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

  • [2024-07-26 10:54:47]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3892kb
  • [2024-07-26 10:54:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int main() {
	string piece = "KQRRBBNN";
	sort(piece.begin(), piece.end());
	vector<string> cand;
	do {
		// the king is placed between the two rooks
		int l = piece.find('R');
		int r = piece.find_last_of('R');
		int k = piece.find('K');
		if (k < l || k > r) {
			continue;
		}
		// the white bishop s are placed on opposite-colored squares
		int b1 = piece.find('B');
		int b2 = piece.find_last_of('B');
		if (b1 % 2 == b2 % 2) {
			continue;
		}
		cand.push_back(piece);
	} while (next_permutation(piece.begin(), piece.end()));


	string str;
	while (cin >> str) {
		if (str == "END") {
			break;
		}
		cin >> *new int;
		auto cur = cand;

		while (1) {
			double best = numeric_limits<double>::max();
			string base;
			if (cur.size() == 960) {
				base = "RBBNNQKR";
			} else {
                // DONE UP HERE
				for (auto x : cur) {
					array<int, 9> freq{};
					for (auto y : cur) {
						int cnt = 0;
						for (int i = 0; i < 8; i++) {
							if (x[i] == y[i]) {
								cnt++;
							}
						}
						freq[cnt]++;
					}
					double sum = 0;
					for (int x : freq) {
						if (x) {
							sum += x * 1e9;
						}
					}
					if (sum < best) {
						best = sum;
						base = x;
					}
				}
			}
			cout << base << endl;
			int num;
			cin >> num;
			if (num == 8) {
				break;
			}
			vector<string> ncur;
			for (auto x : cur) {
				int cnt = 0;
				for (int i = 0; i < 8; i++) {
					if (x[i] == base[i]) {
						cnt++;
					}
				}
				if (cnt == num) {
					ncur.push_back(x);
				}
			}
			cur = move(ncur);
		}
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3892kb

input:

GAME 1
2
0
0
4
8
END

output:

RBBNNQKR
BBNNRKRQ
NNBRKBQR
RKQBNRBN
RKRBBQNN

result:

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

Test #2:

score: -100
Time Limit Exceeded

input:

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

output:

RBBNNQKR
BBNNRKRQ
NNBRKBQR
RKQBNRBN
RKRBBQNN
RBBNNQKR
BBNQRKRN
BNQRKBNR
NRBKQNRB
QRKBNRBN
RKRBBNQN
RBBNNQKR
BBNQRKRN
NNBRKRQB
QRKBBNNR
RKRBBNNQ
RBBNNQKR
BBNQRKRN
BNQRKBNR
NRBKQNRB
RKRBQNBN
RBBNNQKR
BBNNRKQR
NRBKNQRB
RKBBNRNQ
RKRBNQBN
RBBNNQKR
BBNNRKRQ
BNRBKQNR
NBQRKNBR
NQNBBRKR
RKRBNNBQ
RBBNNQKR
BBN...

result: