求助站外题(违规紫衫
  • 板块灌水区
  • 楼主wushiyan
  • 当前回复4
  • 已保存回复4
  • 发布时间2024/8/14 21:32
  • 上次更新2024/8/15 08:34:22
查看原帖
求助站外题(违规紫衫
1152917
wushiyan楼主2024/8/14 21:32

听同学说听说灌水区dalao很强


Description

超级玛丽战胜各种艰难险阻来到了大厅,他惊喜地看到了公主就在这个大厅里,而且看守的恶龙居然不在!

这个大厅的划分为 N∗MN*M 个格子,超级玛丽在格子 (1,1)(1,1),公主在格子(N,M)( N,M)。超级玛丽每一步只能移动到与所在格子上下左右相邻的格子中。超级玛丽需要到达公主的位置才能成功解救公主。

但是有的格子是安全的,而有的格子是陷阱。还好超级玛丽已经吃下了一个蘑菇,所以如果他踩到了一次陷阱也不会危及到生命,只是会变成萌版的小玛丽。但如果是小玛丽踩到陷阱的话,那就Game Over了!

超级玛丽最少需要经过几个格子才能解救出公主?(起点、陷阱、终点都计算在内)

Input Format

第1行2个整数:N,MN,M(1≤N,M≤20001≤N,M≤2000)。

以下第 2~N+12~N+1 行,对应第 1~N1~N 行格子,每行M个数字,0 表示迷宫对应格子是安全的,1 表示对应格子为陷阱 (保证起点和终点不是陷阱)。

Output Format

11 行 11 个整数:最少经过的格子,如果无解,则输出:no answer


輸入資料 1

5 5      
0 0 0 0 0
1 1 1 0 1
0 0 0 0 0
0 0 1 1 1
0 0 0 0 0

輸出資料 1

9

WA_code

#include<bits/stdc++.h>
using namespace std;
int n, m;
int dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
char s[2002][2002];
int dis[2002][2002];
struct node{
	int x, y,life;
	node(int _x, int _y,int _life)
	{
		x = _x;
		y = _y;
        life=_life;
	}
};

int bfs(int x, int y,int l)
{
	queue<node> q;
	q.push(node(x, y,l));
	dis[x][y] = 0;
	while (!q.empty())
	{
		node now = q.front();
        q.pop();
		if (now.x==n-1&&now.y==m-1){
			return dis[now.x][now.y];
		}
		for (int i = 0; i < 4; i++)
		{
			int tx = now.x + dir[i][0], ty = now.y + dir[i][1];
            int tl=(s[tx][ty]=='1'?now.life-1:now.life);
			if (tx < 0 || tx >= n || ty < 0 || ty >= m || tl<=0 || dis[tx][ty] != 0x3f3f3f3f){
				continue;
			}
			dis[tx][ty] = dis[now.x][now.y] + 1;
			q.push(node(tx, ty,tl));
		}
	}
	return -114514;
}
int main()
{
	cin >> n >>m;
	for (int i = 0; i < n; i++){
		for(int j=0;j<m;j++){
            cin>>s[i][j];
        }
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			dis[i][j] = 0x3f3f3f3f;
		} 
	}
	int sssss=bfs(0,0,2);
	if(sssss!=-114514){
		cout<<sssss+1;
	}else{
        cout<<"no answer";
    }
	return 0;
}

样例跑得动,一交上去就不行了(在这里致歉没有测评机的样例),而且还看不到分数。


到底是谁还在悠闲打 Markdown 和 KaTeX\KaTeX 啊

2024/8/14 21:32
加载中...