社区讨论
求助40分wa
P2689东南西北参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mi7xlyx8
- 此快照首次捕获于
- 2025/11/21 05:16 4 个月前
- 此快照最后确认于
- 2025/11/21 05:16 4 个月前
CPP
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int sx,sy,ex,ey,t;
char c[100];
int dfs(int x,int y,int s)
{
if(x==ex&&y==ey)
return 0;
if(s+1>=t)
return -1;
char m=c[s];
int a=x,b=y;
if(m=='N')
a--;
if(m=='S')
a++;
if(m=='E')
b--;
if(m=='W')
b++;
return min(dfs(x,y,s+1),dfs(a,b,s+1)+1);
}
int main()
{
cin>>sx>>sy;
cin>>ex>>ey;
cin>>t;
for(int i=0;i<t;i++)
{
cin>>c[i];
}
int ans=dfs(sx,sy,0);
cout<<ans;
return 0;
}
1a,2w,3w,4a,5w.
回复
共 1 条回复,欢迎继续交流。
正在加载回复...