大佬们,
在线等,挺急的!!!
by tzxxzt @ 2022-07-15 18:56:13
o2啊
by BantM @ 2022-07-15 18:57:51
@[tzxxzt](/user/690561)
开O2
by BantM @ 2022-07-15 18:58:14
@[Bant_Metor](/user/389729)
队内赛不让用O2。
by tzxxzt @ 2022-07-15 19:00:43
@[Bant_Metor](/user/389729)
9个MLE了
by tzxxzt @ 2022-07-15 19:01:14
@[Bant_Metor](/user/389729)
正常做题开O2能过
by tzxxzt @ 2022-07-15 19:01:56
@[Bant_Metor](/user/389729)
我多提交了几遍就过了,谢谢大佬(~~这题太魔幻了吧~终究是我太蒻了吗~~)
by tzxxzt @ 2022-07-15 19:07:36
不懂就问,为什么第一个代码能过???(不开O2)
```cpp
#include<iostream>
using namespace std;
int n, m, t, s1x, s1y, f1x, f1y, a1n1s = 0, t1x, t1y, a[10][10], b[10][10];
int d1x[] = {-1, 1, 0, 0};
int d1y[] = {0, 0, -1, 1};
void DFS(int x, int y) {
if(x == f1x && y == f1y) {
a1n1s++;
return;
}
for(int i = 0; i < 4; i++) {
int x1x = x + d1x[i];
int y1y = y + d1y[i];
if((x1x >= 1 && x1x <= n && y1y >= 1 && y1y <= m )&& a[x1x][y1y] == 0) {
a[x1x][y1y] = 1;
DFS(x1x, y1y);
a[x1x][y1y] = b[x1x][y1y];
}
}
}
int main() {
cin >> n >> m >> t >> s1x >> s1y >> f1x >> f1y;
for(int i = 1; i <= t; i++) {
cin >> t1x >> t1y;
a[t1x][t1y] = 1;
b[t1x][t1y] = 1;
}
a[s1x][s1y] = 1;
DFS(s1x, s1y);
cout << a1n1s;
return 0;
}
```
------------
```cpp
#include<iostream>
using namespace std;
int n, m, t, s1x, s1y, f1x, f1y, a1n1s = 0, t1x, t1y, a[10][10], b[10][10], x1x, y1y;
int d1x[] = {-1, 1, 0, 0};
int d1y[] = {0, 0, -1, 1};
void DFS(int x, int y) {
if(x == f1x && y == f1y) {
a1n1s++;
return;
}
for(int i = 0; i < 4; i++) {
x1x = x + d1x[i];
y1y = y + d1y[i];
if((x1x >= 1 && x1x <= n && y1y >= 1 && y1y <= m )&& a[x1x][y1y] == 0) {
a[x1x][y1y] = 1;
DFS(x1x, y1y);
a[x1x][y1y] = b[x1x][y1y];
}
}
}
int main() {
cin >> n >> m >> t >> s1x >> s1y >> f1x >> f1y;
for(int i = 1; i <= t; i++) {
cin >> t1x >> t1y;
a[t1x][t1y] = 1;
b[t1x][t1y] = 1;
}
a[s1x][s1y] = 1;
DFS(s1x, s1y);
cout << a1n1s;
return 0;
}
```
by tzxxzt @ 2022-07-15 19:14:17
@[tzxxzt](/user/690561)
因为第二个代码xlx和yly开的是全局变量,DFS下一个点的时候就变了,之后再用就不是原来的值了(~~感觉哪里怪怪的~~)
by tzxxzt @ 2022-07-16 08:25:47