Moocryption

题目描述

Unbeknownst to many, cows are quite fond of puzzles, particularly word puzzles. Farmer John's cows have recently created a fun "word finder" puzzle. An example of a such a puzzle is:

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.

输入

The first line of input contains N and M, describing the number of rows and columns of the puzzle (both are at most 50). The next N lines each contain M characters, describing one row of the encrypted puzzle. Each character is an uppercase letter in the range A..Z.

输出

Please output the maximum possible number of MOOs contained in the puzzle if decrypted with an appropriate 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的更多相关文章

随机推荐

  1. Sublime text 3 如何格式化HTML代码

    使用Sublime text 3 编写代码是一种享受,使用Sublime text 3 格式化HTML代码,需要安装插件,具体安装步骤如下:   1.打开菜单->首选项->插件控制,输入 ...

  2. 数论+dp Codeforces Beta Round #2 B

    http://codeforces.com/contest/2/problem/B 题目大意:给你一个n*n的矩形,问从(1,1)出发到(n,n),把图中经过的所有的数字都乘在一起,最后这个数字有多少 ...

  3. VMware设置NAT网络

    很多初学者迷茫与如何实现虚拟机VMware与主机互联,这里小编介绍下简单实用的NAT网络. 工具/原料   VMware 方法/步骤   打开VMware,选择  编辑, 虚拟网络编辑器 默认情况下, ...

  4. byte数组转16进制 输出到文件

    try { File file = new File(Environment.getExternalStorageDirectory(),"shuju2"); if(!file.e ...

  5. openCV(四)---Canny边缘检测

    图像的边缘检测的原理是检测出图像中所有灰度值变化较大的点,而且这些点连接起来就构成了若干线条,这些线条就可以称为图像的边缘. 直接上代码,函数简介都在代码注释中 //canny边缘检测 -(void) ...

  6. ActiveMQ-CPP编译

    1.activemq-cpp下载地址: http://activemq.apache.org/cms/download.html 2.相关依赖库 http://mirrors.hust.edu.cn/ ...

  7. git 使用系列(二)---- 分支和合并

    Branching and Merging The Git feature that really makes it stand apart from nearly every other SCM o ...

  8. for in 的各种坑

    for in方法用来遍历数组或者对象的显性属性,就是说我们自己定义的属性都是可以遍历的,而对象固有的属性,比如Object.prototype.toString是遍历不出来的. for in方法简洁好 ...

  9. 学习笔记:GLSL Core Tutorial – Pipeline (OpenGL 3.2 – OpenGL 4.2)

    GLSL Core Tutorial – Pipeline (OpenGL 3.2 – OpenGL 4.2) GLSL 是一种管道,一种图形化的流水线 1.GLSL 的具体工作流程: 简化流程如下: ...

  10. 用PHP与XML进行网站编程

    一.小序 HTML简单易学又通用,一般的PHP程序就是嵌入在HTML语言之中实现的.但是随着WEB越来越广泛的应用,HTML的弱点也越来越明显了.XML的出现,弥补了这些不足,它提供了一个能够处理互联 ...