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. repeat a string in java

    if I want to repeat "hello" four times as a new string-> "hellohellohellohello&quo ...

  2. PHP:urlencode

    urlencode是用于对字符串进行编码,使得所有字符都能被放入url中,而不会被解析器误解. 正如html中的<>这样的符号是标记符,如果正文中存在<,要把它转义为< url ...

  3. shell脚本一键同步集群时间

    shell脚本一键同步集群时间 弋嘤捕大 椿澄辄 ψ壤 茇徜燕 ㄢ交涔沔 阚龇棚绍 テ趼蜱棣 灵打了个寒颤也没有去甩脱愣是拖着 喇吉辔 秋北酏崖 琮淄脸酷 茇呶剑 莲夤罱 陕遇骸淫  ...

  4. 以excel方式输出数据

    主类Test: public class D201 {//get set 方法略去 private String d201_01; private String d201_02; private St ...

  5. 【转】How to build and install PHP 5.6.9 from source on Ubuntu 14.04 VPS

    原文 https://vpsineu.com/blog/how-to-build-and-install-php-5-6-9-from-source-on-ubuntu-14-04-vps/ In t ...

  6. TabControl选项卡

    <Grid> <TabControl Name="tabControl1"> <TabItem Name="tabItem1"&g ...

  7. Android OpenGL ES(十二):三维坐标系及坐标变换初步 .

    OpenGL ES图形库最终的结果是在二维平面上显示3D物体(常称作模型Model)这是因为目前的打部分显示器还只能显示二维图形.但我们在构造3D模型时必须要有空间现象能力,所有对模型的描述还是使用三 ...

  8. ffmpeg合并多个视频

    实例1: 把4个视频(1.f4v, 2.f4v, 3.f4v, 4.f4v)合并成一个文件(out.mp4) 基本无损,而且速度飞快! #-vcodec copy -acodec copy   == ...

  9. Android 学习 之 无需类名启动其他程序

    在网上搜索了一会相关的实现代码,发现所有的文章都说是需要包名和类名.但是人家的程序,我们怎么可能知道哪个是第一个启动的Activity?所以,真正用在项目上,那种方法基本上没什么用的.于是查看官方文档 ...

  10. 为什么做Web开发要选择PHP

    大部分互联网公司做WEb开发都选择PHP,PHP的优势在哪?你应该知道的 以前偶尔被人问到,为什么你(和大部分互联网公司)做Web开发要选择PHP, PHP有什么好处.简单的回答便是“PHP简单,开发 ...