Moocryption
Moocryption
题目描述
USOPEN
OOMABO
MOOMXO
PQMROM
Being cows, their only word of interest is "MOO", which can appear in the word finder in many places, either horizontally, vertically, or diagonally. The example above contains 6 MOOs.
Farmer John is also a fan of word puzzles. Since the cows don't want him to solve their word finder before they have a chance to try it, they have encrypted its contents using a "substitution cipher" that replaces each letter of the alphabet with some different letter. For example, A might map to X, B might map to A, and so on. No letter maps to itself, and no two letters map to the same letter (since otherwise decryption would be ambiguous).
Unfortunately, the cows have lost track of the substitution cipher needed to decrypt their puzzle. Please help them determine the maximum possible number of MOOs that could exist in the puzzle for an appropriate choice of substitution cipher.
输入
输出
样例输入
4 6
TAMHGI
MMQVWM
QMMQSM
HBQUMQ
样例输出
6
提示
This is the same puzzle at the beginning of the problem statement after a cipher has been applied. Here "M" and "O" have been replaced with "Q" and "M" respectively.
分析:枚举每个点,对每个点,枚举他的8个方向,注意起点不能是M,终点不能是O了;
代码:
#include <bits/stdc++.h>
#define ll long long
const int maxn=1e5+;
using namespace std;
int n,m,k,t,ma,p[][];
char a[][];
int dis[][]={,,,-,,,-,,,-,,,-,,-,-};
void check(int x,int y)
{
for(int i=;i<;i++)
{
int s[],t[];
s[]=x+dis[i][];
s[]=x+dis[i][]*;
t[]=y+dis[i][];
t[]=y+dis[i][]*;
if(s[]>=&&s[]<n&&t[]>=&&t[]<m&&a[x][y]!=a[s[]][t[]]&&a[s[]][t[]]==a[s[]][t[]]&&a[x][y]!='M'&&a[s[]][t[]]!='O')
ma=max(ma,++p[a[x][y]][a[s[]][t[]]] );
}
}
int main()
{
int i,j;
scanf("%d%d",&n,&m);
for(i=;i<n;i++)scanf("%s",a[i]);
for(i=;i<n;i++)
for(j=;j<m;j++)
{
check(i,j);
}
printf("%d\n",ma);
//system("pause");
return ;
}
Moocryption的更多相关文章
随机推荐
- PHP:preg_replace
关于preg_match: http://www.cnblogs.com/helww/p/3466720.html 关于preg_match_all:暂时没有完整的 preg_replace_call ...
- Git中的merge命令实现中出现问题及其解决
Git中的merge命令实现和工作方式 2015年8月17日星期一 丹丹 git代码在合并两个分支的时候总是会出现一下的错误提示,不能正常的完成合并分支,错误提示如图所示: 但是在其他的终端是可以完成 ...
- Hibernate创建SessionFactory实例
private static SessionFactory sessionFactory = null; static { Configuration configuration =new Con ...
- SQL 比较中文字符串
/* declare @str1 varchar(200),@str2 varchar(200) set @str1=N'江西省南昌市其它区高新区火炬大道809号' set @str2=N'江西省南昌 ...
- Js根据class名替换html标签内容 ,在某标签前后添加内容
function getClass(obj, attr) { var aArray = [];//定义一个新的空数组 var i = 0; var aAll = document.getElement ...
- js判断字符串中是否有数字和字母
var p = /[0-9]/; var b = p.test(string);//true,说明有数字var p = /[a-z]/i; var b = p.test(string);//true, ...
- servlet容器开发要点
v1 是一个http服务器. v2 是一个servlet容器, 可以提供servlet的服务. => 动态load servlet字节码,并运行它( 按生命周期). servlet容器它来 ...
- HDOJ3743<分治>
题意:求一个排列的逆序数. #include<cstdio> #include<iostream> #include<algorithm> const int ma ...
- ubuntu中安装myeclipse提示Insufficient Memory解决方法
经过查看资料发现出现这个问题的原因是因为计算机中swap分区的内存不足,或者没有创建swap分区,google中http://www.bkjia.com/webzh/1003601.html提供了一种 ...
- python 第三章 字符串-例1
1.字段宽度和精度 >>>'%.*s' % (10,'Gruido') ' Guido' >>>'%.-*s' % (10,'Gruido') 'Guido ...