反恐精英

24 篇文章 0 订阅
19 篇文章 0 订阅

反恐精英

时间限制: 3 Sec  内存限制: 128 MB
提交: 107  解决: 28
[提交] [状态] [讨论版] [命题人:外部导入]

题目描述

反恐精英是一款流行的射击游戏。
游戏中有两方势力:恐怖分子方和反恐精英方。你所扮演的是反恐精英,需要制服所有恐怖分子,并且拆除c4炸弹。

为了简化问题,假设所有恐怖分子已经被制服。剩下要做的,是在给定t(t<=1000)时间内,到达炸弹所在地点,拆除炸弹。即从起始点( sx,sy )到达炸弹所在的( ex,ey )点。

你会得到一个n*m(2<=n,m<=100)的地图,地图上的每一个点用一个自然数表示,代表地图该点的高度。

每做一次移动,你能到与所在点相邻的,上、下、左、右的任意一个点。
有两种移动方式:

1)普通移动:所耗费的时间是:|垂直高度差|+1。
(例:从( x,y)移动到( x+1,y),耗费时间为 |height(x,y)-height(x+1,y)|+1 )

2)跳跃移动:从高度较高的点移动到较低的点,可以直接跳跃,消耗1点的时间,并损失与高度差等量的血量。
(例:从( x,y )移动到( x,y+1),并且height(x,y)>height(x,y+1),那么你可以选择跳跃,耗费1点时间, height(x,y)-heith(x,y+1)血量)

游戏开始你有100点血量,血量<=0时意味着死亡。

输入

输入的第一行是一个整数T(T<=20),代表有T组数据。

每组数据的第一行是七个整数n,m,sx,sy,ex,ey,t,所表示的意义见题目描述。
下面紧跟n行,每行m个数字,height(i,j)(<=100)表示点(i,j)的高度。
地图最左上角的点为(0,0)点。

输出

如果你能在给定时间内到达目的地,输出 "Run, Forrest, run!",并在下一行输出到达目的地的最快时间。否则输出"Terrorists win!"。

样例输入

4
1 2 0 0 0 1 1
100 1
1 2 0 0 0 1 1
101 1
1 2 0 0 0 1 101
101 1
1 2 0 0 0 1 1
1 100

样例输出

Run, Forrest, run!
1
Terrorists win!
Run, Forrest, run!
101
Terrorists win!

 

一个人物有走的时间,血量和位置,3个属性

所以可以开一个3维dp数组来存状态前俩个表示状态,后一个表示当前血量用的时间

# if 01
# include <iostream>
# include <numeric>
# include <algorithm>
# include <functional>
# include <list>
# include <map>
# include <set>
# include <stack>
# include <deque>
# include <queue>
# include <vector>
# include <ctime>
# include <cstdlib>
# include <cmath>
# include <string>
# include <cstring>
# include <iomanip>
# include <queue>
# include <cstdio>

using namespace std;
const int maxn = 105;
int mp[maxn][maxn];
const int maxx = 0x3f3f3f3f;
int dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
int book[maxn][maxn][maxn];
int n, m, sx, sy, ex, ey, t;
struct node
{
    int x, y, blood;
};
void bfs()
{
    queue<struct node> q;
    struct node temp, front;
    front.x = sx;
    front.y = sy;
    front.blood = 100;
    q.push(front);
    book[sx][sy][100] = 0;
    while(!q.empty())
    {
        temp = q.front();
        q.pop();
        for(int i = 0; i < 4; i++)
        {
            int tx = dir[i][0] + temp.x;
            int ty = dir[i][1] + temp.y;
            if(tx < 0 || tx >= n || ty < 0 || ty >= m)
            {
                continue;
            }
            int t1 = book[temp.x][temp.y][temp.blood] + abs(mp[tx][ty] - mp[temp.x][temp.y]) + 1;
            front.x = tx;
            front.y = ty;
            front.blood = temp.blood;

            //普通的方式
            if(book[tx][ty][front.blood] > t1 && t1  <= t)
            {
                book[tx][ty][front.blood] = t1;

                q.push(front);
            }

            //跳跃的方式
            if(mp[tx][ty] < mp[temp.x][temp.y])
            {
                int t2 = book[temp.x][temp.y][temp.blood] + 1;
                front.blood =  front.blood - (mp[temp.x][temp.y] - mp[tx][ty]);

                if(front.blood > 0)
                {
                    if(book[tx][ty][front.blood] > t2 && t2 <= t)
                    {
                        book[tx][ty][front.blood] = t2;

                        q.push(front);
                    }
                }
            }
        }
    }
}
void fun()
{
    for(int i = 0; i < maxn; i++)
    {
        for(int j = 0; j < maxn; j++)
        {
            for(int k = 0; k < maxn; k++)
            {
                book[i][j][k] = maxx;
            }
        }
    }
}
int find()
{
    int mm = maxx;
     for(int i = 0; i < maxn; i++)
    {
        if(mm > book[ex][ey][i])
            mm = book[ex][ey][i];
    }
    return mm;
}

int main(int argc, char *argv[])
{
    int T;
    while(scanf("%d", &T)!=EOF)
    {
        while(T--)
        {
            fun();
            scanf("%d%d%d%d%d%d%d",&n, &m, &sx, &sy,  &ex, &ey, &t);
            for(int i = 0; i < n; i++)
            {
                for(int j = 0; j  < m; j++)
                {
                    scanf("%d", &mp[i][j]);
                }
            }
            bfs();
            int flag = find();
        //    cout <<  "flag = " << endl;
            if(flag == maxx)
                cout << "Terrorists win!" << endl;
            else
            {
                cout << "Run, Forrest, run!" << endl;
                cout << flag << endl;
            }

        }
    }

    return 0;
}
#endif

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值