我#1答案和输出一模一样
结果
wrong answer Too short on line 2.
无法理解了。
#include <bits/stdc++.h>
using namespace std;
struct node
{
bool f;
int a, b;
}pd[1510][1510];
char g[1510][1510], ch;
int n, m;
bool dfs(int x,int y, int px, int py)
{
if(g[x][y] == '#')
return false;
//cout<<x<<' '<<y<<' '<<px<<' '<<py<<endl;
if(pd[x][y].f)
if(pd[x][y].a == px && pd[x][y].b == py) return false;
else return true;
else
{
pd[x][y].f = 1;
pd[x][y].a = px;
pd[x][y].b = py;
if(x + 1 > n)
{if(dfs(1, y, px + 1, py)) return true;}
else if(dfs(x + 1, y, px, py)) return true;
if(x - 1 < 1)
{if(dfs(n, y, px - 1, py)) return true;}
else if(dfs(x - 1, y, px, py)) return true;
if(y + 1 > m)
{if(dfs(x, 1, px, py + 1)) return true;}
else if(dfs(x, y + 1, px, py)) return true;
if(y - 1 < 1)
{if(dfs(x, m, px, py - 1)) return true;}
else if(dfs(x, y - 1, px, py)) return true;
return false;
}
}
int x, y;
int main()
{
//freopen("ooo.in", "w", stdout);
while(scanf("%d%d", &n, &m))
{
memset(g, 0, sizeof(g));
//memset(pd, 0, sizeof(node));
scanf("%c", &ch);
//cout<<n<<' '<<m;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
scanf("%c", &g[i][j]);
pd[i][j].f = 0;
//cout<<i<<' '<<j<<endl;
if(g[i][j] == 'S')
{
x = i;
y = j;
}
}
scanf("%c", &ch);
}
//cout<<x<<' '<<y<<g[x][y]<<endl;
if(dfs(x, y, 0, 0))puts("Yes");
else puts("No");
}
}
就算我这个程序确实还有问题,但起码给我#1过吧?
这答案正确判我错我就不能理解了。