当前位置:网站首页>AcWing 1874. Moo encryption (enumeration, hash)
AcWing 1874. Moo encryption (enumeration, hash)
2022-04-23 11:26:00 【Eurya song】
【 Title Description 】
Many people don't know , Cows love jigsaw puzzles , Especially word puzzles .
Farmer John's cow recently invented an interesting “ Word Finder ” Puzzle .
An example of this puzzle is :
USOPEN
OOMABO
MOOMXO
PQMROM
As a cow , The only words they are interested in are MOO
, It can move horizontally several times in the puzzle 、 vertical 、 45 45 45 Degree slash or 135 135 135 Degree slash appears .
In the above example ,MOO
All in all 6 6 6 Time .
Farmer John is also a puzzle fan , Because the cows don't want him to solve it before them “ Word Finder ” Puzzle , So they use ” Replace password “ The content is encrypted .
The “ Replace password ” Replaced each letter in the alphabet with a different letter .
for example , A A A Can be mapped to X X X, B B B Can be mapped to A A A, And so on .
No letters map to themselves , Nor do two letters map to the same letter ( Otherwise, the solution will be ambiguous ).
Unfortunately , The cow forgot the specific encryption method of replacing the password .
Please help them determine if decryption with the appropriate replacement password , The biggest possible problem in the puzzle MOO
Count .
【 Input format 】
The first line contains N , M N,M N,M, Indicates that the size of the puzzle is N N N That's ok M M M Column .
Next N N N That's ok , Each row contains M M M Capital letters , Describe the encrypted puzzle .
【 Output format 】
Output if decrypted with the appropriate replacement password , The biggest possible problem in the puzzle MOO
Count .
【 Data range 】
1 ≤ N , M ≤ 50 1≤N,M≤50 1≤N,M≤50
【 sample input 】
4 6
TAMHGI
MMQVWM
QMMQSM
HBQUMQ
【 sample output 】
6
【 Sample explanation 】
In this example , M M M and O O O Are replaced by Q Q Q and M M M.
Therefore, decryption can exist at most 6 6 6 individual MOO
.
【 analysis 】
We can map any letter to another letter , But it can't be mapped to itself , So all ABB
Type and not MOO
All strings can be mapped to MOO
.
Enumeration starts at each point , Then enumerate the length that can be constructed by extending in eight directions 3 3 3 String , If the constructed string s s s Form like ABB
, A string that is not the first letter of M
, The last two letters are not O
, Then put the string s s s The number of occurrences plus one . Finally, the most frequent occurrence of all qualified strings is the answer .
【 Code 】
#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
#include <unordered_map>
using namespace std;
const int N = 60;
char g[N][N];
unordered_map<string, int> cnt;// All in the shape of ABB And A Not for M、B Not for O The number of strings
int n, m;
int dx[8] = {
-1, -1, -1, 0, 1, 1, 1, 0 };
int dy[8] = {
-1, 0, 1, 1, 1, 0, -1, -1 };
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> g[i];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
{
for (int d = 0; d < 8; d++)
{
string s;
s += g[i][j];
int x = i, y = j;
bool flag = true;// If you cross the line, then flag by false
for (int u = 0; u < 2; u++)
{
x += dx[d], y += dy[d];
if (x < 0 || x >= n || y < 0 || y >= m) {
flag = false; break; }
s += g[x][y];
}
if (flag && s[0] != s[1] && s[1] == s[2] && s[0] != 'M' && s[1] != 'O') cnt[s]++;
}
}
int res = 0;
for (auto& [k, v] : cnt) res = max(res, v);
cout << res << endl;
return 0;
}
版权声明
本文为[Eurya song]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231117579297.html
边栏推荐
- 详解MySQL中timestamp和datetime时区问题导致做DTS遇到的坑
- nacos基础(6):nacos配置管理模型
- How does QT turn qwigdet into qdialog
- 解决 『SunCertPathBuilderException:unable to find valid certification path to requested target』 问题
- Interprocess communication -- message queue
- Résumé de la relation entre GPU, cuda et cudnn
- AcWing 1874. 哞加密(枚举,哈希)
- MySQL对数据表已有表进行分区表的实现
- Detailed explanation of how to smoothly go online after MySQL table splitting
- docker MySQL主从备份
猜你喜欢
随机推荐
Write console script by laravel
分享两个实用的shell脚本
MQ在laravel中简单使用
Mysql排序的特性详情
MQ is easy to use in laravel
Learning go language 0x01: start from the official website
系统编程之高级文件IO(十三)——IO多路复用-select
Compress the curl library into a sending string of utf8 and send it with curl library
Laravel绑定钉钉群警报(php)
MySQL Router重装后重新连接集群进行引导出现的——此主机中之前已配置过的问题
Applet payment
qt5. 8. You want to use SQLite in the 64 bit static library, but the static library has no method to compile the supporting library
Laravel增加自定义助手函数
Learning go language 0x08: practice using error in go language journey
Detailed explanation of MySQL creation stored procedure and function
防止web项目中的SQL注入
学习 Go 语言 0x06:《Go 语言之旅》中 斐波纳契闭包 练习题代码
Learn go language 0x03: understand the dependency between variables and initialization order
MySQL partition table can be classified by month
Upgrade the functions available for cpolar intranet penetration