acm编程问题;

acm编程问题;

题目
acm编程问题;
题意:S到T的最短路径,但是行走过程中改变方向的话步数要加1,输出最小步数,不能到达输出-1;
测试数据:
Sample Input
2
5 5
#####
#...#
#.#.#
#S#T#
#####
4 5
#.#.#
#.#.#
#S#T#
#####
Sample Output
8
-1
以下是我的代码:
#include
#include
#include
#include
#include
using namespace std;
struct node{
int x,y;
int step;
char fx;
};
char map[110][110];
int dir[4][2]={{0,1},{1,0},{-1,0},{0,-1}};
int num[120];
int n,m;
int sx,sy,dx,dy;
bool flag;
node f;
int k1;
int bfs()
{
int i,j,k;
int tx,ty;
char temp;
int sstep;
queueq;
node front,rear;
while(!q.empty())q.pop();
q.push(f);
while(!q.empty())
{
front=q.front();
q.pop();
if(front.x==dx&&front.y==dy){
num[k1++]=front.step;
flag=1;
}
map[front.x][front.y]='#';
for(i=0;i
答案
测试数据可以通过……有什么不对吗
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
热门考点

超级试练试题库

© 2017-2019 超级试练试题库,All Rights Reserved.