HLG2035广搜

Diablo
Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 42(21 users) Total Accepted: 23(20 users) Rating: Special Judge: No
Description

Diablo是地狱中的三大魔王之一,有着非常强大的破坏力,Diablo期望着可以将一切都投入到地狱之中。为了不让Diablo的计划得逞,一位英雄决定挺身而出,试图击败Diablo。DIablo喜欢把眼前的区域变成一片火海,Diablo吐出火焰的蔓延是有一定规律的,火焰总是会向能量较低的区域蔓延。英雄如果不想被Diablo击败的话,就需要在Diablo喷出火焰的一瞬间逃到火焰烧不到的地方,但是他只能在这一瞬逃出3个单位长度的距离。现在我们给出现场的一个地图,并且给出Diablo和英雄所在的位置,我们要知道英雄是否可以逃脱Diablo的攻击。(火焰蔓延方向只能是上、下、左、右)

Input
本题有多组测试数据,对于每组数据第一行输入6个非负整数,分别表示地图的长、宽(分别对应m、n),Diablo的坐标以及英雄的坐标。接下来n行每行输入m个数,表示地图上每个点的能量值(值在32位有符号整数范围内)。m、n值均不大于100,且我们保证数据合理合法。
Output
如果英雄可以逃脱Diablo的攻击,输出Hero will be back并换行,否则输出Diablo win并换行。
Sample Input

3 3 0 0 2 2
5 4 1
4 3 2
3 2 1

 

6 4 0 0 2 3
5 2 6 7 3 0
4 3 8 1 5 5
9 1 8 3 6 5
8 7 6 5 4 2

Sample Output

Diablo win

Hero will be back

 

Hint
我们来看看第二组样例数据,Diablo所处的位置是(0, 0),那么Diablo在地图上左上角的点,其能量值为5。英雄所在的位置是(2, 3),也就是我们看到地图上第三行第四列的位置,其能量值为3。不过火焰只能从能量高的地方向能量低的地方蔓延,尽管英雄处在的位置能量值较低,但是火焰却无法蔓延到这里,因为有能量相对较高的地势阻隔。假设英雄所在的位置能被火焰蔓延到,他只需在3步内找到一个火焰不可达的合法区域即可躲过攻击。
Source
2014 Winter Holiday Contest 5
Author
杨和禹

 

 

 

 

 

 

 

代码

 

 

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int m,n;
int a[105][105],book[105][105],b[105][105];
struct node
{
    int x;
    int y;

} que[30000];
int pd(int endx,int endy)
{
    for(int i=0; i<=3; i++)
       {

       for(int j=3-i; j>=0; j--)
            {for(int k=0; k<=3; k++)
            {
                int mx,my;
                if(k==0)
                {
                    mx=i;
                    my=j;
                }
                else if(k==1)
                {
                    mx=-i;
                    my=j;
                }
                else if(k==2)
                {
                    mx=i;
                    my=-j;
                }

                else
                {
                    mx=-i;
                    my=-j;
                }

                if(endx+mx>=0&&endx+mx<=m-1&&endy+my>=0&&endy+my<=n-1&&b[endx+mx][endy+my]==0)
                    return 0;

            }}}
    return 1;
}
int main()
{
    int startx,starty,endx,endy;
    while(scanf("%d%d%d%d%d%d",&n,&m,&startx,&starty,&endx,&endy)!=EOF)
    {
        memset(a,0,sizeof(a));
        memset(book,0,sizeof(book));
        for(int i=0; i<m; i++)
            for(int j=0; j<n; j++)
                scanf("%d",&a[i][j]);
        int next[4][2]= {1,0,0,-1,-1,0,0,1};
        int head=1,tail=1;
        que[head].x=startx;
        que[head].y=starty;

        book[startx][starty]=1;
        b[startx][starty]=1;
        tail++;
        int flag=0;
        while(head<tail)
        {
            for(int k=0; k<4; k++)
            {
                int tx=que[head].x+next[k][0];
                int ty=que[head].y+next[k][1];
                if(tx<0||tx>m-1||ty<0||ty>n-1)
                    continue;
                if(book[tx][ty]==0&&a[tx][ty]<a[startx][starty])
                {
                    que[tail].x=tx;
                    que[tail].y=ty;
                    b[tx][ty]=1;
                    book[tx][ty]=1;
                    tail++;
                }
                if(tx==endx&&ty==endy)
                {
                    flag=1;
                }
            }
            head++;
        }
        if(flag==1&&pd(endx,endy))
        {

            printf("Diablo win\n");
        }
        else if(startx==endx&&starty==endy)
        {
             printf("Diablo win\n");
        }
        else
            printf("Hero will be back\n");
    }
    return 0;
}

 

posted @ 2015-04-15 16:17  柳下_MBX  阅读(232)  评论(0编辑  收藏  举报