hdu 5254(暴力穷举)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5254


解题思路:暴力枚举即可,没什么好讲的。


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

const int maxn = 505;
int n,m,g,map[maxn][maxn];

bool check(int i,int j)
{
	int tmp1 = 0,tmp2 = 0,tmp3 = 0,tmp4 = 0;
	if(i > 1 && map[i-1][j] == 1)
		tmp1 = 1;
	if(i < n && map[i+1][j] == 1)
		tmp2 = 1;
	if(j > 1 && map[i][j-1] == 1)
		tmp3 = 1;
	if(j < m && map[i][j+1] == 1)
		tmp4 = 1;
	if(tmp1 == 1 && tmp3 == 1) return true;
	if(tmp1 == 1 && tmp4 == 1) return true;
	if(tmp2 == 1 && tmp3 == 1) return true;
	if(tmp2 == 1 && tmp4 == 1) return true;
	return false;
}

int main()
{
	int t,x,y,cas = 1;
	scanf("%d",&t);
	while(t--)
	{
		memset(map,0,sizeof(map));
		scanf("%d%d",&n,&m);
		scanf("%d",&g);
		while(g--)
		{
			scanf("%d%d",&x,&y);
			map[x][y] = 1;
		}
		while(true)
		{
			bool ok = true;
			for(int i = 1; i <= n; i++)
				for(int j = 1; j <= m; j++)
					if(map[i][j] == 0 && check(i,j))
					{
						map[i][j] = 1;
						ok = false;
					}
			if(ok) break;
		}
		int ans = 0;
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= m; j++)
				if(map[i][j])
					ans++;
		printf("Case #%d:\n%d\n",cas++,ans);
	}
	return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值