ぶっきらぼうに貴方は言った
记对手状态
考虑构造一个自动机,状态
考虑枚举每个起点,每次默认
namespace Loop1st {
map<int, int> mp = {{'R', 0}, {'P', 1}, {'S', 2}};
int n, vis[N][210];
struct DFA {
int tot, c[N], to[N][3];
void print() {
cout << tot << '\n';
for (int i = 1; i <= tot; i++) {
cout << (c[i] == 0 ? 'R' : (c[i] == 1 ? 'P' : 'S')) << ' ';
cout << max(1, to[i][0]) << ' ' << max(1, to[i][1]) << ' ' << max(1, to[i][2]) << '\n';
}
}
} A, B;
void buildM() {
for (int i = 1; i <= n; i++) {
int u = ++A.tot;
A.c[u] = (B.c[i] + 1) % 3;
A.to[u][B.c[i]] = A.tot - i + B.to[i][A.c[u]];
}
}
void build(int s) {
int u = 1, v = s;
while (!vis[u][v]) { // 出现环就说明赢了
vis[u][v] = 1;
int x = A.c[u], y = B.c[v];
if (!A.to[u][y]) {
buildM();
A.to[u][y] = A.tot - n + B.to[v][x];
}
u = A.to[u][y];
v = B.to[v][x];
}
}
void Main(int tc) {
cin >> n;
for (int i = 1; i <= n; i++) {
char ch; cin >> ch >> B.to[i][0] >> B.to[i][1] >> B.to[i][2];
B.c[i] = mp[ch];
}
buildM();
for (int i = 1; i <= n; i++) build(i);
A.print();
}
}