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. SQL SERVER 2000 遍历父子关系数据的表(二叉树)获得所有子节点 所有父节点及节点层数函数

    ---SQL SERVER 2000 遍历父子关系數據表(二叉树)获得所有子节点 所有父节点及节点层数函数---Geovin Du 涂聚文--建立測試環境Create Table GeovinDu([ ...

  2. BIND rndc—使用说明

    rndc—使用说明        rndc设置(本地) 产生/etc/rndc.key     执行”rndc-confgen -a”指令后,会在/etc目录下产生rndc.key文件, 而所产生的文 ...

  3. jquery 高亮

    <ul> <li id="0">冬瓜很好吃</li> <li id="1">西瓜不好吃</li> & ...

  4. centos mono

    wget http://download.mono-project.com/sources/mono/mono-4.0.1.tar.bz2wget http://download.mono-proje ...

  5. replication across two data centers

    http://andyhan.net/index.php/sys-adm/item/291-hbase-replication http://shitouer.cn/2013/04/hbase-mul ...

  6. Java学习笔记之I/O

    package com.chinasofti.javase20160819; import java.io.BufferedReader; import java.io.BufferedWriter; ...

  7. OpenLayer 3 鼠标位置坐标显示控件

    <body> <div id="map"> <div id="mouse-position"></div> &l ...

  8. jsp环境搭建(Windows)

    1.软件准备 JDK 最新版jdk-8u45-windows-x64.exe tomcat 最新版32-bit/64-bit Windows Service Installer Eclipse IDE ...

  9. mysql中exists的用法介绍

    SELECT c.CustomerId, CompanyName   2 FROM Customers c   3 WHERE EXISTS(   4     SELECT OrderID FROM  ...

  10. Loadrunner性能测试分类详(二)

    一.基准测试 有基础的标准,这样能通过对比发现系统的不同点与变化. 1.可以再指定的标准下通过基准测试建立一个性能基准,这样以后当系统的环境.参数发生变化后,再进行一次相同标准下的测试,即可看出变化对 ...