201604-4-游戏

(http://115.28.138.223/view.page?gpid=T39)

bfs适合求最短路 首先记录危险方格的时间 因为100时间之后 所有方格均不危险 
所以最短时间的最大值为300 记录每个坐标每个时间的状态 不超过     300*100*100=3000000直接bfs即可。 
#include<stdio.h>
#include<queue>
using namespace std;
typedef struct
{
    int x, y;
    int t;
}State;//位置 时间 
typedef struct
{
    int l;
    int r;
}Dead;//危险时间段 
Dead s[105][105] = {0};
State temp, now; 
int flag[105][105][305] = {0}, dir[4][2] = {0,1,0,-1,1,0,-1,0};
queue<State> q;
int main(void)
{
    int i, n, m, t, x, y, l, r;
    scanf("%d%d%d", &n, &m, &t);
    for(i=1;i<=t;i++)
    {
        scanf("%d%d%d%d", &x, &y, &l, &r);
        s[x][y].l = l, s[x][y].r = r;
    }
    now.x = now.y = 1, now.t = 0;
    q.push(now);
    while(q.empty()==0)
    {
        now = q.front();
        q.pop();
        if(now.x==n && now.y==m)
            break;
        t = temp.t = now.t+1;
        for(i=0;i<4;i++)
        {
            x = temp.x = now.x+dir[i][0];
            y = temp.y = now.y+dir[i][1];
            if(x>=1&&y>=1&&x<=n&&y<=m&&(t<s[x][y].l||t>s[x][y].r)&&flag[x][y][t]==0)
            {
                q.push(temp);
                flag[x][y][t] = 1;
            }
        }
    }
    printf("%d\n", now.t);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值