[ZOJ 3314] CAPTCHA [模拟]

该博客介绍了一个编程挑战,即从300*300的矩阵中识别出可能经过180度旋转的26个英文字母。由于数据范围较小,建议采用暴力枚举方法判断每个位置是否为字母的起点,同时注意字母间的包含关系,如G包含C,R包含P,E包含L等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

给26个字母的样子,和一个300*300的矩阵,让你识别出里边都有什么字母...每个字母都不超过7*16。需要识别出180度旋转后的字母。

数据范围很小,直接暴力枚举当前位置开始的是不是一个字母即可。

注意G完全包含C,R完全包含P,E完全包含L....其他的就没什么trick了...

#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

char table[26][7][17]={
	{
"111111MMM1111111",
"11111MM1MM111111",
"1111MM111MM11111",
"111MMMMMMMMM1111",
"11MM1111111MM111",
"1MMM11111111MM11",
"1MM1111111111MM1"
	},{
"1MMMMMMMMMMM1111",
"1MM11111111MM111",
"1MM11111111MM111",
"1MMMMMMMMMMM1111",
"1MM11111111MM111",
"1MM11111111MM111",
"1MMMMMMMMMMM1111"
	},{
"11111MMMMMMMM111",
"111MM1111111MM11",
"11MM111111111MM1",
"11MM111111111111",
"11MM111111111MM1",
"111MM1111111MM11",
"11111MMMMMMMM111"
	},{
"1MMMMMMMMMMM1111",
"1MM111111111MM11",
"1MM1111111111MM1",
"1MM1111111111MM1",
"1MM1111111111MM1",
"1MM111111111MM11",
"1MMMMMMMMMMM1111"
	},{
"1MMMMMMMMMMMM111",
"1MM1111111111111",
"1MM1111111111111",
"1MMMMMMMMMMMM111",
"1MM1111111111111",
"1MM1111111111111",
"1MMMMMMMMMMMM111"
	},{
"1MMMMMMMMMMMMM11",
"1MM1111111111111",
"1MM1111111111111",
"1MMMMMMMMMMMMM11",
"1MM1111111111111",
"1MM1111111111111",
"1MM1111111111111"
	},{
"11111MMMMMMMM111",
"111MM1111111MM11",
"11MM111111111MM1",
"11MM111111111111",
"11MM111111MMMMM1",
"111MM1111111MM11",
"11111MMMMMMMMM11"
	},{
"1MM111111111MM11",
"1MM111111111MM11",
"1MM111111111MM11",
"1MMMMMMMMMMMMM11",
"1MM111111111MM11",
"1MM111111111MM11",
"1MM111111111MM11"
	},{
"11111MMMMMM11111",
"1111111MM1111111",
"1111111MM1111111",
"1111111MM1111111",
"1111111MM1111111",
"1111111MM1111111",
"11111MMMMMM11111"
	},{
"1111MMMMMMMM1111",
"1111111MM1111111",
"1111111MM1111111",
"1111111MM1111111",
"111MM11MM1111111",
"111MMM1MM1111111",
"11111MMMM1111111"
	},{
"11MM111111MMM111",
"11MM11111MMM1111",
"11MM111MMM111111",
"11MMMMM111111111",
"11MM111MMM111111",
"11MM11111MMM1111",
"11MM111111MMMM11"
	},{
"11MM111111111111",
"11MM111111111111",
"11MM111111111111",
"11MM111111111111",
"11MM111111111111",
"11MM111111111111",
"11MMMMMMMMMMMM11"
	},{
"1MM1111111111MM1",
"1MMMM111111MMMM1",
"1MM1MM1111MM1MM1",
"1MM11MMMMM111MM1",
"1MM1111M11111MM1",
"1MM1111111111MM1",
"1MM1111111111MM1"
	},{
"1MMM111111111MM1",
"1MMMM11111111MM1",
"1MM1MM1111111MM1",
"1MM11MM111111MM1",
"1MM1111MM1111MM1",
"1MM111111MMM1MM1",
"1MM11111111MMMM1"
	},{
"11111MMMMMM11111",
"111MMM1111MMM111",
"11MMM111111MMM11",
"1MM1111111111MM1",
"11MMM111111MMM11",
"111MMM1111MMM111",
"11111MMMMMM11111"
	},{
"1MMMMMMMMMMM1111",
"1MM111111111MM11",
"1MM1111111111MM1",
"1MM111111111MM11",
"1MMMMMMMMMMM1111",
"1MM1111111111111",
"1MM1111111111111"
	},{
"11111MMMMMM11111",
"111MMM1111MMM111",
"11MMM111111MMM11",
"1MM1111111111MM1",
"11MMM1MMMM1MMM11",
"111MMM11MMMMM111",
"111111MMMM1MMMM1"
	},{
"1MMMMMMMMMMM1111",
"1MM111111111MM11",
"1MM1111111111MM1",
"1MM111111111MM11",
"1MMMMMMMMMMM1111",
"1MM11111111MM111",
"1MM111111111MMM1"
	},{
"1111MMMMMMMM1111",
"111MM1111111MM11",
"11MMM1111111MMM1",
"1111MMMMM1111111",
"1MMM111MMMM11111",
"111MMM11111MMM11",
"11111MMMMMMM1111"
	},{
"11MMMMMMMMMMMM11",
"11MMMMMMMMMMMM11",
"1111111MM1111111",
"1111111MM1111111",
"1111111MM1111111",
"1111111MM1111111",
"1111111MM1111111"
	},{
"1MM1111111111MM1",
"1MM1111111111MM1",
"1MM1111111111MM1",
"1MM1111111111MM1",
"1MMM11111111MMM1",
"1MMM11111111MMM1",
"111MMMMMMMMMM111"
	},{
"1MMMM111111MMMM1",
"11MMM111111MMM11",
"11MMM111111MMM11",
"111MMM1111MMM111",
"1111MMM11MMM1111",
"11111MM11MM11111",
"111111MMMM111111"
	},{
"1MM1111111111MM1",
"1MM1111111111MM1",
"11MM111MM111MM11",
"11MM111MM111MM11",
"11MM111MM111MM11",
"11MM1MM11MM1MM11",
"111MMM1111MMM111"
	},{
"11MMM111111MMM11",
"111MMM1111MMM111",
"1111MMM11MMM1111",
"111111MMMM111111",
"1111MMM11MMM1111",
"111MMM1111MMM111",
"11MMM111111MMM11"
	},{
"11MMM111111MMM11",
"111MMM1111MMM111",
"1111MMM11MMM1111",
"111111MMMM111111",
"1111111MM1111111",
"1111111MM1111111",
"1111111MM1111111"
	},{
"111MMMMMMMMMM111",
"1111111111MM1111",
"111111111MM11111",
"11111111MM111111",
"111111MM11111111",
"11111MM111111111",
"111MMMMMMMMMMM11"
	}};

vector<pair<int,int> > have1[26];
vector<pair<int,int> > have2[26];
bool ans[26];
char s[300][301];
int n,m;

void print(char a[7][17]) {
	for (int j=0;j<7;j++) {
		for (int k=0;k<16;k++)
			if (a[j][k]=='M') printf("*");
			else printf(" ");
		printf("\n");
	}
	printf("\n");
}
int caltopx(char c[7][17]) {
	for (int i=0;i<7;i++)
		for (int j=0;j<16;j++)
			if (c[i][j]=='M') return i;
}
int caltopy(char c[7][17]) {
	for (int j=0;j<16;j++)
		for (int i=0;i<7;i++)
			if (c[i][j]=='M') return j;
}
void cal(char c[7][17],vector<pair<int,int> > &have) {
	//print(c);
	int i,j,topx=caltopx(c),topy=caltopy(c);
	//printf("top: (%d,%d)\n",topx,topy);
	for (i=0;i<7;i++) 
		for (j=0;j<16;j++)
			if (c[i][j]=='M') {
				have.push_back(make_pair(i-topx,j-topy));
				//printf("%d %d\n",i-topx,j-topy);
			}
}
inline bool in(int x,int y) {
	return x>=0&&y>=0&&x<n&&y<m;
}
bool is(vector<pair<int,int> > &have,int x,int y) {
	for (int i=0;i<have.size();i++) {
		int tmpx=x+have[i].first,tmpy=y+have[i].second;
		if (!in(tmpx,tmpy)) return false;
		if (s[tmpx][tmpy]!='M') return false;
	}
	return true;
}

int main() {
	int i,j,k;
	for (i=0;i<26;i++)
		cal(table[i],have1[i]);
	for (i=0;i<26;i++) {
		for (j=0;j+j<6;j++) {
			for (k=0;k<16;k++) {
				swap(table[i][j][k],table[i][6-j][15-k]);
			}
		}
		for (k=0;k+k<16;k++)
			swap(table[i][3][k],table[i][3][15-k]);
	}
	for (i=0;i<26;i++)
		cal(table[i],have2[i]);
	while (scanf("%d%d",&n,&m)!=EOF) {
		for (i=0;i<n;i++) scanf("%s",s[i]);
		memset(ans,0,sizeof(ans));
		for (i=0;i<n;i++)
			for (j=0;j<m;j++) {
				if (is(have1[4],i,j)||is(have2[4],i,j)) {
					ans[4]=true;
					continue;
				}
				if (is(have1[6],i,j)||is(have2[6],i,j)) {
					ans[6]=true;
					continue;
				}
				if (is(have1[17],i,j)||is(have2[17],i,j)) {
					ans[17]=true;
					continue;
				}
				for (k=0;k<26;k++)
					if (!ans[k]&&(is(have1[k],i,j)||is(have2[k],i,j))) ans[k]=true;
			}
		for (i=0;i<26;i++)
			if (ans[i]) printf("%c",i+'A');
		printf("\n");
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值