紫书UVa1103

在这里插入图片描述

#include <vector>
#include <map>
#include<algorithm>
#include<cmath>
#include<set>
#include<cstdio>
#include <sstream>
#include <string>
#include<iostream>
#include<iomanip>
#include<stack>
#include<utility>
#include<unordered_map>
#include<queue>
#include<cstring>
#include <list>
#include<deque>
using namespace std;

const int maxn = 200+5;
int pic[maxn][maxn];//原图
int m, n;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
char word[7] = { "WAKJSD" };
int cur;
const int offset = 2;//防止拷贝后的黑色联通块触及边界

bool isin(const int r, const int c)
{
	return r >= 0 && r <= m + offset && c >= 0 && c <= 4 * n + offset;
}
void DFS1(const int r, const int c) {
	if (!isin(r, c) || pic[r][c] != 0) return;
	pic[r][c] = '-';
	for (int i = 0; i < 4; ++i)
		DFS1(r + dx[i], c + dy[i]);
}
void DFS2(const int r, const int c) {
	if (!isin(r, c) || pic[r][c] != 1) return;
	pic[r][c] = '-';
	for (int i = 0; i < 4; ++i){
		int r1 = r + dx[i], c1 = c + dy[i];
		if (pic[r1][c1] == 0) {
			++cur;
			DFS1(r1, c1);
		}
		else DFS2(r1, c1);
	}
}
int main()
{
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int kase = 0;
	while (scanf("%d%d", &m, &n) == 2 && m && n)
	{
		vector<char>out;
		getchar();
		char ch;
		int num;
		int cnt = 0;
		memset(pic, 0, sizeof(pic));
		for (int k = 0; k < m; ++k)
		{
			for (int i = 0; i < n; ++i)
			{
				ch = getchar();
				if (isalpha(ch))
				{
					num = ch - 'a' + 10;
				}
				else
					num = ch - '0';
				for (int j = 3; j >= 0; --j)
				{
					pic[k+1][i * 4 +j+1] = num % 2;
					num /= 2;
				}
			}
			getchar();
		}
		DFS1(0, 0);
		for (int i = 1; i <= m; ++i) {
			for (int j = 1; j <= 4*n; ++j) {
				if (pic[i][j] != 1) continue;
				cur = 0;
				DFS2(i, j);
				out.push_back(word[cur]);
			}
		}
		printf("Case %d: ", ++kase);
		sort(out.begin(), out.end());
		for (char elem : out)
		{
			printf("%c", elem);
		}
		puts("");
	}
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

进击的程序

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值