主函数:读图,读方向,将方向转为数字编号存进a数组,进入bfs,输出图
by Mutsumi_0114 @ 2018-07-24 10:38:42
发现你连
5 5
.....
.....
.....
.....
.....
3
NORTH
WEST
NORTH
都好像错了
by w23c3c3 @ 2018-07-24 11:09:19
哦
右下角改成“*”
……打错了
by w23c3c3 @ 2018-07-24 11:10:00
5 5
.....
.....
.....
.....
....*
3
NORTH
WEST
NORTH
.....
.....
.....
.....
.....
--------------------------------
Process exited after 25.52 seconds with return value 0
Press any key to continue . . .
by w23c3c3 @ 2018-07-24 11:10:42
看看
by Mutsumi_0114 @ 2018-07-24 11:11:40
@[w23c3c3](/space/show?uid=109942) 感谢了一直找不到hack数据
by Mutsumi_0114 @ 2018-07-24 11:12:20
看看好像没什么问题
by w23c3c3 @ 2018-07-24 11:16:01
代码改完,准备提交
```
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
struct node
{
int r,c,step;
}n;
int R,C,N,a[1005],zl[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
char g[55][55],f[5][10]={"NORTH","SOUTH","WEST","EAST"},temp[10];
queue <node> q;
void bfs()
{
while(!q.empty())
{
int u=q.front().r;
int v=q.front().c;
int s=q.front().step;
q.pop();
if(s==N)
break;
if(g[u][v]==s+'0')
g[u][v]='.';
for(int i=u+zl[a[s]][0],j=v+zl[a[s]][1];g[i][j]!='X';i+=zl[a[s]][0],j+=zl[a[s]][1])
{
n.r=i;
n.c=j;
n.step=s+1;
q.push(n);
g[i][j]=s+1+'0';
}
}
return;
}
int main()
{
scanf("%d%d",&R,&C);
memset(g,'X',sizeof(g));
for(int i=1;i<=R;i++)
for(int j=1;j<=C;j++)
{
scanf(" %c",&g[i][j]);
if(g[i][j]=='*')
{
n.r=i;
n.c=j;
n.step=0;
q.push(n);
g[i][j]='.';
}
}
scanf("%d",&N);
for(int i=0;i<N;i++)
{
scanf(" %s",temp);
for(int j=0;j<4;j++)
if(!strcmp(f[j],temp))
{
a[i]=j;
break;
}
}
bfs();
for(int i=1;i<=R;i++)
{
for(int j=1;j<=C;j++)
if(g[i][j]>='0' && g[i][j]<='9')
printf("*");
else
printf("%c",g[i][j]);
printf("\n");
}
return 0;
}
```
by Mutsumi_0114 @ 2018-07-24 11:23:07
五颜六色表示放弃治疗
by Mutsumi_0114 @ 2018-07-24 11:25:44
错了?
by w23c3c3 @ 2018-07-24 11:28:47