2017华东师范大学网赛-袋鼠妈妈找孩子

袋鼠妈妈找孩子

Time limit per test: 1.5 seconds

Time limit all tests: 10.0 seconds

Memory limit: 256 megabytes

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

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

请设计这样一个迷宫。

Input

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

第二行三个整数  x,y,k   (1xn,1ym,x+y>1)

Output

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

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

数据保证有解。

Examples

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

Source

2017 华东师范大学网赛
解题思路:数据较小,可以爆搜,先将所有格子变为墙,然后走出一条路就好


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <bitset>
#include <set>
#include <vector>
#include <functional>

using namespace std;

#define LL long long
const int INF = 0x3f3f3f3f;

char ch[15][15];
int n, m;
int dir[4][2] = { {1,0},{-1,0},{0,1},{0,-1} };

int dfs(int x, int y, int step,int limit)
{
	if (x == 1 && y == 1 && step >= limit) return true;
	for (int i = 0; i < 4; i++)
	{
		int xx = x + dir[i][0], yy = y + dir[i][1],sum=0;
		if (xx <= 0 || yy <= 0 || xx > n || yy > m||ch[xx][yy]!='*') continue;
		for (int j = 0; j < 4; j++)
			if (ch[xx + dir[j][0]][yy + dir[j][1]] == '.') sum++;
		if (sum > 1) continue;
		ch[xx][yy] = '.';
		if (dfs(xx, yy, step + 1, limit)) return true;
		ch[xx][yy] = '*';
	}
	return false;
}

int main()
{
	while (~scanf("%d%d", &n, &m))
	{
		memset(ch, 0, sizeof ch);
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= m; j++)
				ch[i][j] = '*';
		int x, y, k;
		scanf("%d%d%d", &x, &y, &k);
		ch[x][y] = '.';
		dfs(x, y, 0,k);
		for (int i = 1; i <= n; i++)
			printf("%s\n", ch[i] + 1);
	}
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值