编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#46103 #1153. wch和zxh的游♂戏 Compile Error 0 0 ms 0 K C++ / 1.1 K 233nihao 2020-08-17 11:12:19
显示原始代码
#include <iostream>
#include <math.h>
using namespace std;
int a[4][4];
int temps[10000];
int coun = 0;
int dfs(int x, int m, int count) {
    int temp = 0;
    temp = count;
    cout << temp << endl;
    if (m == 0) {
        temps[coun] = temp;
        coun++;
        return temp;
    }
    if (m > 0) {
        for (int i = 0; i < 9; i++) {
            temp += left(i);
            dfs(i, m - 1, temp);
            temp -= right(i);
        }
    }
}
int left(int x2) {
    int xx = x2 % 3;
    int yy = x2 / 3;
    int temp = a[xx][yy];
    a[xx][yy] = a[xx + 1][yy];
    a[xx + 1][yy] = a[xx + 1][yy + 1];
    a[xx + 1][yy + 1] = a[xx][yy + 1];
    a[xx][yy + 1] = temp;
    int u = (a[xx][yy] + a[xx + 1][yy] + a[xx][yy + 1] + a[xx + 1][yy + 1]);
    return u;
}
int right(int x) {
    int xx = x % 3;
    int yy = x / 3;
    int temp = a[xx][yy];
    a[xx][yy] = a[xx][yy + 1];
    a[xx][yy + 1] = a[xx + 1][yy + 1];
    a[xx + 1][yy + 1] = a[xx + 1][yy];
    a[xx + 1][yy] = temp;
    return (a[xx][yy] + a[xx + 1][yy] + a[xx][yy + 1] + a[xx + 1][yy + 1]);
}
int main() {
    int n, m;
    cin >> n;
    while (n--) {
        cin >> m;
        coun = 0;
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                cin >> a[i][j];
            }
        }
        dfs(0, 2 * m, 0);
        for (int p = 0; p < pow(9, 2 * m); p++) cout << temps[p] << " ";
    }
}

编译信息

/sandbox/1/a.cpp: In function 'int dfs(int, int, int)':
/sandbox/1/a.cpp:22:15: error: invalid initialization of reference of type 'std::ios_base&' from expression of type 'int'
    temp+=left(i);
               ^
In file included from /usr/include/c++/8/ios:42,
                 from /usr/include/c++/8/ostream:38,
                 from /usr/include/c++/8/iostream:39,
                 from /sandbox/1/a.cpp:1:
/usr/include/c++/8/bits/ios_base.h:1001:3: note: in passing argument 1 of 'std::ios_base& std::left(std::ios_base&)'
   left(ios_base& __base)
   ^~~~
/sandbox/1/a.cpp:24:16: error: invalid initialization of reference of type 'std::ios_base&' from expression of type 'int'
    temp-=right(i);
                ^
In file included from /usr/include/c++/8/ios:42,
                 from /usr/include/c++/8/ostream:38,
                 from /usr/include/c++/8/iostream:39,
                 from /sandbox/1/a.cpp:1:
/usr/include/c++/8/bits/ios_base.h:1009:3: note: in passing argument 1 of 'std::ios_base& std::right(std::ios_base&)'
   right(ios_base& __base)
   ^~~~~
/sandbox/1/a.cpp:27:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^