ECNU-3260

来源:互联网 发布:网络言情小说家排名 编辑:程序博客网 时间:2024/05/20 06:31

袋鼠妈妈找孩子
Time limit per test: 1.5 seconds
Time limit all tests: 10.0 seconds
Memory limit: 256 megabytes

袋鼠妈妈找不到她的孩子了。她的孩子被怪兽抓走了。

袋鼠妈妈现在在地图的左上角,她的孩子在地图第 x 行第 y 列的位置。怪兽想和袋鼠妈妈玩一个游戏:他不想让袋鼠妈妈过快地找到她的孩子。袋鼠妈妈每秒钟可以向上下左右四个方向跳一格(如果没有墙阻拦的话),怪兽就要在一些格子中造墙,从而完成一个迷宫,使得袋鼠妈妈能够找到她的孩子,但最快不能小于 k 秒。

请设计这样一个迷宫。

Input
第一行两个整数 n,m (1≤n,m≤8),表示地图的总行数和总列数。

第二行三个整数 x,y,k (1≤x≤n,1≤y≤m,x+y>1)。

Output
输出一个地图,应正好 n 行 m 列。

用 . 表示空地,用 * 表示墙。袋鼠妈妈所在的位置和孩子所在的位置用 . 表示。

数据保证有解。

Examples
input
2 6
1 3 4
output
..**
……

题意:构造一个步数超过k的通路到达目标点。
思路:还是菜啊,。。看了题解想了想懂了。。我们只需要找到一条距离超过k的就可以了,那么如果我当前位置要往前走,对走到的那个格子来说,如果只有之前那个格子可以走,那么必定是可行的,这是个充分条件,满足这个条件必定是可以的,但是你在旁边再加格子不一定不可行。码的时候注意,步数是不小于k。。我写成了等于。。贼迷。。还有图上可走是*不是#…这里我也错了。。
不懂的话可以调用我的debug看看。。。反正就是从一堆不能走的路走出一条长度大于k的路2333

#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<vector>#include<cmath>#include<cstdio>#include<cstring>#include<string>#include<stack>#include<map>using namespace std;//thanks to pyf ...#define INF 0x3f3f3f3f#define CLR(x,y) memset(x,y,sizeof(x))#define mp(x,y) make_pair(x,y)typedef pair<int, int> PII;typedef long long ll;const int N = 1e6 + 5;char Map[10][10];int vis[10][10][100];int xdir[4] = {0, 1, 0, -1};int ydir[4] = {1, 0, -1, 0};int k = 0;int tx, ty;int flag = 0;int n, m;void init(){    for (int i = 0; i < n; i++)    {        for (int j = 0; j < m; j++)        {            Map[i][j] = i == 0 && j == 0 ? '.' : '*';        }    }}bool judge(int x, int y){    int cnt = 0;    for (int i = 0; i < 4; i++)    {        int tx = x + xdir[i] ;        int ty = y + ydir[i];        if (tx < 0 || tx >= n || ty < 0 || ty >= m)            continue;        if (Map[tx][ty] == '.')            cnt++;    }    return cnt == 1;}void debug(){    for (int i = 0; i < n; i++)    {        for (int j = 0; j < m; j++)        {            cout << Map[i][j];        }        cout << endl;    }    cout << endl;}void dfs(int i, int j, int step){    if (flag)        return;    Map[i][j] = '.';    if (i == tx && j == ty)    {        if (step >= k)        {            flag = 1;            for (int x = 0; x < n; x++)            {                for (int y = 0; y < m; y++)                    cout << Map[x][y];                cout << endl;            }        }        Map[i][j] = '*';        return ;    }//  debug();    for (int k = 0; k < 4; k++)    {        int tx = i + xdir[k];        int ty = j + ydir[k];        if (tx < 0 || tx >= n || ty < 0 || ty >= m || Map[tx][ty] == '.')            continue;        if (judge(tx, ty))            dfs(tx, ty, step + 1);    }    Map[i][j] = '*';}int main(){    while (cin >> n >> m)    {        flag = 0;        cin >> tx >> ty >> k;        tx--, ty--;        init();        flag = 0;        dfs(0, 0, 0);    }}
0 0
原创粉丝点击