日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Moocryption

發布時間:2025/6/17 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

總結

以上是生活随笔為你收集整理的Moocryption的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。