#include <iostream>
#include <string>
#include <vector>
using namespace std;
// Funkcja zwraca wynik z perspektywy gracza A
// 1: A wygrywa, -1: B wygrywa, 0: remis
int get_res(char a, char b) {
if (a == b) return 0;
if ((a == 'P' && b == 'K') || (a == 'K' && b == 'N') || (a == 'N' && b == 'P')) return 1;
return -1;
}
void solve() {
string identity;
int n, t;
if (!(cin >> identity >> n >> t)) return;
bool isAlgosia = (identity == "Algosia");
for (int test_case = 0; test_case < t; ++test_case) {
string my_bits;
cin >> my_bits;
string his_bits = "";
int diff = 0; // score_Algosia - score_Bajtek
for (int i = 0; i < n; ++i) {
char a_move, b_move;
// --- RUNDA 1: Algosia wysyła bit ---
if (isAlgosia) {
// Algosia koduje: 0 -> P, 1 -> K
a_move = (my_bits[i] == '0' ? 'P' : 'K');
cout << a_move << endl;
cin >> b_move;
} else {
// Bajtek odbiera: musi grać tak, by nie wygrać meczu (nie zrobić diff -2)
// Jeśli Algosia prowadzi (diff > 0), Bajtek gra P (zremisuje z P lub wygra z K)
// Jeśli Algosia traci (diff <= 0), Bajtek gra K (przegra z P lub zremisuje z K)
b_move = (diff > 0 ? 'P' : 'K');
cout << b_move << endl;
cin >> a_move;
his_bits += (a_move == 'P' ? '0' : '1');
}
diff += get_res(a_move, b_move);
// --- RUNDA 2: Bajtek wysyła bit ---
if (isAlgosia) {
// Algosia odbiera: musi grać tak, by nie wygrać meczu (nie zrobić diff +2)
a_move = (diff < 0 ? 'P' : 'K');
cout << a_move << endl;
cin >> b_move;
his_bits += (b_move == 'P' ? '0' : '1');
} else {
// Bajtek koduje: 0 -> P, 1 -> K
b_move = (my_bits[i] == '0' ? 'P' : 'K');
cout << b_move << endl;
cin >> a_move;
}
diff += get_res(a_move, b_move);
}
cout << "! " << his_bits << endl;
cout.flush();
}
}
int main() {
// Nie używamy sync_with_stdio(false), aby mieć pewność co do flushowania
solve();
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #include <iostream> #include <string> #include <vector> using namespace std; // Funkcja zwraca wynik z perspektywy gracza A // 1: A wygrywa, -1: B wygrywa, 0: remis int get_res(char a, char b) { if (a == b) return 0; if ((a == 'P' && b == 'K') || (a == 'K' && b == 'N') || (a == 'N' && b == 'P')) return 1; return -1; } void solve() { string identity; int n, t; if (!(cin >> identity >> n >> t)) return; bool isAlgosia = (identity == "Algosia"); for (int test_case = 0; test_case < t; ++test_case) { string my_bits; cin >> my_bits; string his_bits = ""; int diff = 0; // score_Algosia - score_Bajtek for (int i = 0; i < n; ++i) { char a_move, b_move; // --- RUNDA 1: Algosia wysyła bit --- if (isAlgosia) { // Algosia koduje: 0 -> P, 1 -> K a_move = (my_bits[i] == '0' ? 'P' : 'K'); cout << a_move << endl; cin >> b_move; } else { // Bajtek odbiera: musi grać tak, by nie wygrać meczu (nie zrobić diff -2) // Jeśli Algosia prowadzi (diff > 0), Bajtek gra P (zremisuje z P lub wygra z K) // Jeśli Algosia traci (diff <= 0), Bajtek gra K (przegra z P lub zremisuje z K) b_move = (diff > 0 ? 'P' : 'K'); cout << b_move << endl; cin >> a_move; his_bits += (a_move == 'P' ? '0' : '1'); } diff += get_res(a_move, b_move); // --- RUNDA 2: Bajtek wysyła bit --- if (isAlgosia) { // Algosia odbiera: musi grać tak, by nie wygrać meczu (nie zrobić diff +2) a_move = (diff < 0 ? 'P' : 'K'); cout << a_move << endl; cin >> b_move; his_bits += (b_move == 'P' ? '0' : '1'); } else { // Bajtek koduje: 0 -> P, 1 -> K b_move = (my_bits[i] == '0' ? 'P' : 'K'); cout << b_move << endl; cin >> a_move; } diff += get_res(a_move, b_move); } cout << "! " << his_bits << endl; cout.flush(); } } int main() { // Nie używamy sync_with_stdio(false), aby mieć pewność co do flushowania solve(); return 0; } |
English