为什么在自己电脑运行和洛谷答案不一样
  • 板块P1605 迷宫
  • 楼主ashore_
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/12/24 14:11
  • 上次更新2024/12/24 14:14:49
查看原帖
为什么在自己电脑运行和洛谷答案不一样
811016
ashore_楼主2024/12/24 14:11
#include <bits/stdc++.h>
using namespace std;
int sq[6][6];
int n, m, t;
int bx, by, ex, ey;
int u, v, total;
bool visited[6][6];
int dir[4][2] = {
    {1, 0},
    {0, 1},
    {0, -1},
    {-1, 0},
};
void dfs(int x, int y) {
  if (x == ex && y == ey) {
    ++total;
    return;
  }
  for (int i = 0; i < 4; ++i) {
    int tx = x + dir[i][0];
    int ty = y + dir[i][1];
    /*
    下面代码改成这个就对了。

    if (visited[tx][ty] || sq[tx][ty] == 0) continue;
    和
    if (visited[tx][ty]==0 && sq[tx][ty] == 1){}
    不是逆否命题吗?

      if (visited[tx][ty]==0 && sq[tx][ty] == 1) {
	    visited[x][y] = 1;
	    dfs(tx, ty);
	    visited[x][y] = 0;
    }*/
    if (visited[tx][ty] || sq[tx][ty] == 0) continue;
    visited[x][y] = 1;
    dfs(tx, ty);
    visited[x][y] = 0;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr), cout.tie(nullptr);
  cin >> n >> m >> t;
  cin >> bx >> by >> ex >> ey;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) sq[i][j] = 1;
  while (t--) {
    cin >> u >> v;
    sq[u][v] = 0;
  }
  if (sq[ex][ey] == 0) {
    cout << "0" << endl;
    return 0;
  }
  dfs(bx, by);
  cout << total << endl;
  return 0;
}

上面代码为什么在我电脑上就是891,我提交直接AC了呢?

5 5 5 
1 2 5 5
2 1
2 2
2 3
2 4
3 4
2024/12/24 14:11
加载中...