Description
Solution
首先首字母可以通过两次猜测搞出来,我们不妨假设第一个字母为A
,其他情况同理。
设ANS
表示已经猜出来的一个前缀,我们可以press(ANS + BB + ANS + BX + ANS + BY + ANS + X)
。
- 如果返回的值为
len(ANS)
,那么下一个字母为Y
; - 如果返回的值为
len(ANS)+1
,那么下一个字母为X
; - 如果返回的值为
len(ANS)+2
,那么下一个字母为B
;
注意最后一个字母必须用2次来判断,因为上面的方法会超过规定的长度。
Code
/************************************************
* Au: Hany01
* Prob: cambo
* Email: hany01dxx@gmail.com & hany01@foxmail.com
* Inst: Yali High School
************************************************/
#include<bits/stdc++.h>
#include "combo.h"
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
#define rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++ i)
#define For(i, j, k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define x first
#define y second
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define SZ(a) ((int)(a).size())
#define ALL(a) a.begin(), a.end()
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define y1 wozenmezhemecaia
template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
inline int read() {
static int _, __; static char c_;
for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar()) if (c_ == '-') __ = -1;
for ( ; c_ >= '0' && c_ <= '9'; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
return _ * __;
}
string guess_sequence(int N) {
string S, lst[4];
int tot = 0;
//Confirm the first character (2)
if (press("AB")) if (press("A")) S = "A"; else S = "B";
else if (press("X")) S = "X"; else S = "Y";
if (N == 1) return S;
if (S != "A") lst[++ tot] = "A";
if (S != "B") lst[++ tot] = "B";
if (S != "X") lst[++ tot] = "X";
if (S != "Y") lst[++ tot] = "Y";
//The others (n-2)
For(i, 2, N - 1) {
int t = press(S + lst[1] + lst[1] + S + lst[1] + lst[2] + S + lst[1] + lst[3] + S + lst[2]);
if (t == i + 1) S = S + lst[1];
else if (t == i) S = S + lst[2];
else S = S + lst[3];
}
//Deal with the last one specially (2)
if (press(S + "A" + S + "B") == N) {
if (press(S + "A") == N) return S + "A";
else return S + "B";
} else {
if (press(S + "X") == N) return S + "X";
else return S + "Y";
}
}