acm編程問題;
acm編程問題;
題意:S到T的最短路徑,但是行走過程中改變方向的話步數(shù)要加1,輸出最小步數(shù),不能到達(dá)輸出-1;
測試數(shù)據(jù):
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
題意:S到T的最短路徑,但是行走過程中改變方向的話步數(shù)要加1,輸出最小步數(shù),不能到達(dá)輸出-1;
測試數(shù)據(jù):
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
其他人氣:499 ℃時間:2020-07-31 21:02:47
優(yōu)質(zhì)解答
測試數(shù)據(jù)可以通過……有什么不對嗎
我來回答
類似推薦
- 編程ACM的一道題
- It was four days ago____ the man was put into prison again.
- 完全失重的時候為什么水滴成絕對球形
- 高中數(shù)學(xué)排列組合公式Cnm(n為下標(biāo),m為上標(biāo))=n!/m!(n-m)!是怎么來的
- 一個直角三角形的三邊長為連續(xù)偶數(shù),則它各邊長為?勾股定理怎么算出來的啊?
- 我很在乎你 用英文怎么寫
- +500度和-400度的眼鏡片,哪個是近視鏡片它的焦度是多少,焦距是多少
- 已知a
- 唐詩“欲窮千里目,更上一層樓”的意思
- Weather________,I will go mountain climbing.
- 兩段電阻絲的電阻之比是3:2,通過它們的電流之比是1:4,如果使它們產(chǎn)生相同的熱量,通電時間之比是——
- 虛無主義通俗點說是什么?
猜你喜歡
- 1sin(π-θ)+cos(2π-θ)/cos(5π/2-θ)+sin(3π/2+θ)=2,則sinθcosθ=______
- 2一到四年級的古詩
- 3南宋時兩大詞人被譽為“蘇辛”,“蘇”指的是蘇軾,那“辛”指的是哪位豪放派詞人?
- 4數(shù)學(xué)題,誰來幫幫我呀!O(∩_∩)O謝謝!要過程.000
- 5Although laughter ___ the room ,she feilt lonely.
- 6我們腳下的這塊土地也是一本有趣的書(縮句)
- 7形容路途遙遠(yuǎn).——寫一成語
- 8趣味語文小故事
- 9比喻琴聲優(yōu)美動聽的句子
- 10什么叫“四不像”?
- 11怎樣配置火堿消毒液,
- 12求 大工12春《高等數(shù)學(xué)》(上)在線作業(yè)2