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+10;
using namespace std;
int n,m,k,t,ma,p[300][300];
char a[51][51];
int dis[][2]={0,1,0,-1,1,0,-1,0,1,-1,1,1,-1,1,-1,-1};
void check(int x,int y)
{for(int i=0;i<8;i++){int s[2],t[2];s[0]=x+dis[i][0];s[1]=x+dis[i][0]*2;t[0]=y+dis[i][1];t[1]=y+dis[i][1]*2;if(s[1]>=0&&s[1]<n&&t[1]>=0&&t[1]<m&&a[x][y]!=a[s[0]][t[0]]&&a[s[0]][t[0]]==a[s[1]][t[1]]&&a[x][y]!='M'&&a[s[0]][t[0]]!='O')ma=max(ma,++p[a[x][y]][a[s[0]][t[0]]] );}
}
int main()
{int i,j;scanf("%d%d",&n,&m);for(i=0;i<n;i++)scanf("%s",a[i]);for(i=0;i<n;i++)for(j=0;j<m;j++){check(i,j);}printf("%d\n",ma);//system("pause");return 0;
}

转载于:https://www.cnblogs.com/dyzll/p/5769206.html

Moocryption相关推荐

  1. html table边框细线,HTML小技巧将table边框改为细线

    HTML制作新手在用TABLE表格时,会碰到如何改变边线粗线,因为默认的TABLE边线设置即使是1px 是很粗的.因此会使用其他一些方法来制作出细线边框,这里介绍一种利用CSS来实现细线的方法,很有效 ...

最新文章

  1. poj2305-Basic remains(进制转换 + 大整数取模)
  2. java填充二维数组_Java用Arrays.fill()初始化二维数组的实现
  3. Effective Modern C++英文版及中文翻译
  4. 城市大脑标准体系与评价指标总体框架研究
  5. Mind+上传模式的第三方Arduino用户库实现 -DHT11温湿度模块
  6. 小白电商美工(设计师)都该了解一下PSD分层模板
  7. android异步工作,Android异步消息机制详解
  8. windows server 2012 开始菜单
  9. Basic INFO - InstallShield的版本区分
  10. C++ string与vectorfloat类型相互转换之stringstream
  11. 虚机里的vCenter 迁移
  12. 无法使用SQL login去登陆SQL Server - 'Password did not match'
  13. emoji java 转码_Java Emoji Converter (Emoji表情转换工具)
  14. Cesium 获取屏幕所在经纬度范围
  15. 信息系统项目管理师考试后多久出成绩?
  16. Building the main Guest Additions module
  17. java画好看坦克_java绘图,画坦克
  18. 118岁武术家吕紫剑仙逝
  19. xiuno论坛目录结构摸索记录【hook】
  20. Python数据类型及操作

热门文章

  1. [git]通过commit_id找回文件
  2. HttpUrlConnection get和post简单实现(疑惑解决)
  3. 登陆sqlserver及修改端口号
  4. Enable-Migrations出错
  5. Python运维开发基础01-语法基础【转】
  6. 南邮CTF密码学write up
  7. Scrum项目1.0
  8. GitHub上最受欢迎的Android开源项目TOP20
  9. Java Sort中Comparator的语义分析
  10. jQuery鼠标移入移出(冒泡版和无冒泡版)