编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#1703 #993. 汉诺塔问题 Compile Error 0 0 ms 0 K C++ 17 / 991 B t330026143 2023-10-15 16:44:18
显示原始代码
#include <bits/stdc++.h>
using namespace std;
int n, x, f1[100], f2[100], ans, xx;
void dfs(int d, int x, int y, bool kk) {
    int z = 1;
    while (x == z || z == y) z++;
    if (x == y) {
        if (d > 1)
            dfs(d - 1, f1[d - 1], kk ? f2[d - 1] : y, kk && true);
        return;
    }
    if (d > 1)
        dfs(d - 1, f1[d - 1], z, false);
    cout << "move " << d << " from " << char(x + 'A' - 1) << " to " << char(y + 'A' - 1) << endl, ans++;
    f1[d] = y;
    if (d > 1)
        dfs(d - 1, f1[d - 1], kkf2[d - 1] : y, kk && true);
}
int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    cin >> x;
    for (int i = 1; i <= x; i++) cin >> xx, f1[xx] = 1;
    cin >> x;
    for (int i = 1; i <= x; i++) cin >> xx, f1[xx] = 2;
    cin >> x;
    for (int i = 1; i <= x; i++) cin >> xx, f1[xx] = 3;
    cin >> x;
    for (int i = 1; i <= x; i++) cin >> xx, f2[xx] = 1;
    cin >> x;
    for (int i = 1; i <= x; i++) cin >> xx, f2[xx] = 2;
    cin >> x;
    for (int i = 1; i <= x; i++) cin >> xx, f2[xx] = 3;
    dfs(n, f1[n], f2[n], true);
    cout << ans << endl;
}

编译信息

/sandbox/1/a.cpp: In function 'void dfs(int, int, int, bool)':
/sandbox/1/a.cpp:13:29: error: 'kkf2' was not declared in this scope; did you mean 'kk'?
   13 |     if (d>1)dfs(d-1,f1[d-1],kkf2[d-1]:y,kk&&true);
      |                             ^~~~
      |                             kk