CCF认证 2016-04 游戏

求在方格图上从一点到达另一点的最短时间,有边界但是没有障碍,取而代之的是某些方格在一段时间内是不能走的
可能在某段时间会困在一个区域内,每个时间必须走一步,所以可以走回头路
不妨直接在二维平面图的基础上加上时间这个维度,进行三维的bfs搜索,但是时间每走一步都是+1
这样最先到达目标点依然是最快的时间
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
const int N=100+10;
const int M=100+10;
const int T=300+10; //最大可能的时间
const int dx[]={0,0,-1,1};
const int dy[]={-1,1,0,0};
struct node
{
	int x,y,t;
	node(int a,int b,int c)
	{
		x=a;y=b;t=c;
	}
};
bool d[N][M][T];
int l[N][M],r[N][M];
int n,m,k;
int bfs()
{
	queue<node> q;
	q.push(node(1,1,0));
	d[1][1][0]=true;
	while(!q.empty())
	{
		node u=q.front();
		q.pop();
		int ux=u.x,uy=u.y,ut=u.t;
		for(int i=0;i<4;i++)
		{
			int nx=ux+
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值