我已经很尽力地改bug了,只剩一个bug,就是找不找,求帮助
查看原帖
我已经很尽力地改bug了,只剩一个bug,就是找不找,求帮助
1022031
Felixy楼主2023/12/4 19:34

问题:输出0,调试发现处理函数core()core()运行后没有效果。思路:标记每个点走到的方法的种数,m[i][j]=m[i−1][j]+m[i][j−1]m[i][j]=m[i-1][j]+m[i][j-1]

注意: h[]h[]数组没用,里面有一个debug()debug()函数供调试。

代码:

#include <iostream>
#include <iomanip>

using namespace std;


int nx, mx;
int hx, hy;
bool h[11][2];
int m[22][22];

void init() {
    m[hx][hy] = -1;

    m[hx - 1][hy - 2] = -1;
    m[hx + 1][hy - 2] = -1;

    m[hx - 1][hy + 2] = -1;
    m[hx + 1][hy + 2] = -1;

    m[hx - 2][hy + 1] = -1;
    m[hx - 2][hy - 1] = -1;

    m[hx + 2][hy + 1] = -1;
    m[hx + 2][hy - 1] = -1;

    return;
}


bool find_pos(int x, int y) {
    return (m[x][y] == -1);
}

void core() {
    for(int i = 0; i <= nx; i ++) {
        for(int j = 0; j <= mx; j ++) {
            if(! find_pos(i, j)) {
                if((i != 0) && (j != 0)) {
                    m[i][j] = m[i - 1][j] + m[i][j - 1];
                }
                else if((i == 0) && (j == 0)) {
                    m[i][j] = 0;
                }
                else if((i != 0) && (j == 0)) {
                    m[i][j] = m[i - 1][j];
                }
                else if((i == 0) && (j != 0)) {
                    m[i][j] = m[i][j - 1];
                }
                if((m[i - 1][j] == -1) || (m[i][j - 1] == -1)) {
                    m[i][j] = 0;
                }
            }
            else {
                m[i][j] = -1;
            }
        }
    }
    return;
}

void debug() {
    cout << setw(8);
    for(int i = 0; i <= nx; i ++) {
        for(int j = 0; j <=mx; j ++) {
            cout << m[i][j] << setw(8);
        }
        cout << endl;
    }
    return;
}

int main() {
    cin >> nx >> mx >> hx >> hy;

    init();
    //debug();
    core();
    //cout << endl;
    //debug();

    cout << m[nx][mx] << endl;

    return 0;
}

2023/12/4 19:34
加载中...