Moocryption

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值