uva 10977 Enchanted Forest 魔幻森林

应该是比较冷门的一道题,只搜到了英文题解hhhh,难度不大,所以这次来写一个认真的题解报告。
 


You are Ash, the famous Pokemon trainer. To become the greatest Pokemon master, you travel through regions battling against gym leaders and entering Pokemon League competitions. With your well-trained Pikachu, Squirtle and Bulbasaur, you have already captured six badges! What a marvellous performance!

你是神奇宝贝训练大师Ash(推测可能是智爷?)。为了成为更伟大的神奇宝贝训练大师,你在各地旅行并挑战道馆,最终还进入了神奇宝贝联盟赛。与你超强的皮卡丘、杰尼龟和妙蛙种子一起,你已经获得了六个徽章。你表现得真棒!

Now, you are walking through the Enchanted Forest, where the most powerful Pokemons live... No, not those giant dragons; we are actually talking about Jigglypuffs. A Jigglypuff is a normal-type Balloon Pokemon, with a round, balloon-like body, a tuft of fur on its forehead, and stubby arms and legs. What’s so powerful of them? Well, do you notice that microphone in the picture? That’s right, Jigglypuff has a well-regarded singing voice, and its most popular attack is to sing its opponent to sleep! Therefore, it is always a good idea to find a route avoiding places wherever you might hear the Jigglypuffs’ lullaby.

现在你正要穿越 魔幻森林 ,那里住着最强的神奇宝贝。不,不是那些巨龙,事实上我说的是胖丁。胖丁是普通系气球小精灵,它们的身体圆圆的,像气球一样,前额有一撮小刘海,还有短短的四肢。嗯?你问它们强在哪里?好吧,你注意到图片中的麦克风了吗?胖丁的歌声十分有名,它最强大的攻击就是通过唱歌来让它的对手睡觉!因此,穿过这个森林最好的办法是找一条不会听到它们歌声的路。

Let us model the situation as follows: we shall treat the forest as a rectangular grid formed by paths which are 1 unit apart. Your starting position is at the top left corner of the grid (1, 1), and you will leave the forest at the lower right corner (R, C). There might be blocked areas which you are not allowed to trespass through. Jigglypuffs might be present at some intersections. The loudness L of each Jigglypuff is given, which means that places no more than L units away from the Jigglypuff are considered “dangerous” and should be avoided.

让我们把这种情况建模如下:我们将森林视为一个单位长度为1的矩形网格格点。您的起始位置位于网格的左上角(1, 1),出口在在右下角(R,C)。有些点是被岩石阻挡而不能通过。胖丁们站在一些格点上。给出了每个胖丁的响度L,这意味着远离这个胖丁的L个单元的位置被认为是“危险的”并且不能走。


Input

Input consists of several test cases. Each test begins with two integers R and C (1 ≤ R, C ≤ 200), the number of rows and columns in the grid map. Then comes an integer m, followed by m lines each giving the coordinates of a blocked position. Next there is an integer n (0 ≤ n ≤ 100), the number of Jigglypuffs in the forest. The following n lines each gives the position of a Jigglypuff and its loudness L (1 ≤ L ≤ 100). Input ends with a test case where R = 0 and C = 0. You must not process this test case.

Output

For each case, if some “dangerous” places are unavoidable, print ‘Impossible.’ Otherwise, give the length of the shortest path to get out of the forest safely. The figure on the right shows the sample test case. The area enclosed by the blue circle is “dangerous”. The solution shown is unique.

Sample Input

5 5

5

1 2

1 3

1 4

1 5

2 5

1

4 3 1

0 0

Sample Output

8

多组输入

每组输入第一行是迷宫大小R,C(当R=C=0时结束输入)

后跟一行单一个数字表示被岩石阻挡的区域个数

后跟好多行岩石坐标

然后一行单一个数字表示胖丁的个数

后跟好多行 胖丁位置,胖丁声音传播距离



一个简单的迷宫。

因为胖丁而不能走的格子标记不能走就行

我的方法是先划分出一个以胖丁站位为中心的正方形,去遍历其中的每一点与胖丁站位的距离平方,如果小于L平方就标记不能走。

然后就是一个普通的找路bfs。

#include<iostream>
#include<string>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
/*
* I just want to eat
* How tasty it is
*/
int forest[205][205];//好像从(1,1)开始,也就是说边界是[1,n]
int R,C;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
struct step{
    int x,y,len;
};
void bfs(){
    queue<step> q2;
    step s={1,1,0};
    q2.push(s);
    while(!q2.empty()){
        int x= q2.front().x,y= q2.front().y,l= q2.front().len;
        q2.pop();
        if(x==R&&y==C){cout<<l<<endl;return;}
        for(int i=0;i<4;i++){
            int xx=x+dx[i],yy=y+dy[i];
            if(xx<=0||xx>R||yy<=0||yy>C)continue;
            if(forest[xx][yy]==1)continue;
            forest[xx][yy]=1;
            step s={xx,yy,l+1};
            q2.push(s);
        }

    }
    cout<<"Impossible."<<endl;
    return ;
}

int main(){

    while(cin>>R>>C){
            if(R==0)break;
        memset(forest,0,sizeof forest);
        int n,a,b,L;
        cin>>n;
        for(int i = 0;i<n;i++){
            cin>>a>>b;
            forest[a][b]=1;
        }
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>a>>b>>L;
            for(int j = max(a-L,0);j<=min(a+L,R);j++){
                for(int k = max(b-L,0); k<=min(b+L,C);k++){
                   int d1=abs(j-a),d2=abs(k-b);
                   if(d1*d1+d2*d2<=L*L)
                    forest[j][k]=1;
                }

            }
        }
        bfs();
    }

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值