题目:http://39.107.84.82/problem.php?id=1033
MIKU四个字母须按照顺序,通过紧挨着的单元格内的字母组成。紧挨着的单元格是横向相邻或竖向相邻的字母。当然,不允许交叉着找,同时同一个单元格内的字母也不允许被重复使用。
# include "iostream"
# include "string"
# include "cmath"
# include "cstdio"
# include "cstdlib"
# include "algorithm"
#define _for(i,a,b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long int LL;
inline void debug(int n)
{
cout << n << "_Debug" << endl;
return;
}
int main()
{
int m, n;
while (cin >> m >> n)
{
bool is_find = 0;
char in[m + 2][n + 2] = {'0'};
//Input
for (int a = 1; a < m + 1; ++a)
{
for (int b = 1; b < n + 1; ++b)
{
cin >> in[a][b];
}
}
//Judge
int i, j; //M
int k, l; //I
int o, p; //K
int r, s; //U
for (i = 1; i < m + 1; ++i)
{
for (j = 1; j < n + 1; ++j)
{
//Find M
if (in[i][j] == 77)
{
//debug(1);
for (k = i - 1; k < i + 2; ++k)
{
for (l = j - 1; l < j + 2; ++l)
{
//Find I
//printf("i,j = %d %d\n", i,j);
//printf("k,l = %d %d\n", k,l);
if (in[k][l] == 73 && ((k==i&&l==j-1) || (k==i&&l==j+1) || (k==i-1&&l==j) || (k==i+1&&l==j)) && k >= 1 && k <= m && l >= 1 && l <= n)
{
//debug(2);
for (o = k - 1; o < k + 2; ++o)
{
for (p = l - 1; p < l + 2; ++p)
{
//Find K
if (in[o][p] == 75 && ((o==k&&p==l-1) || (o==k&&p==l+1) || (o==k-1&&p==l) || (o==k+1&&p==l)) && o >= 1 && o <= m && p >= 1 && p <= n)
{
//debug(3);
for (r = o - 1; r < o + 2; ++r)
{
for (s = p - 1; s < p + 2; ++s)
{
//Find U
if (in[r][s] == 85 && ((r==o&&s==p-1) || (r==o&&s==p+1) || (r==o-1&&s==p) || (r==o+1&&s==p)) && r >= 1 && r <= m && s >= 1 && s <= n)
{
is_find = 1;
break;
}
}
}
}
}
}
}
}
}
}
}
}
if (is_find == 0)
cout << "zannen" << endl;
else
cout << "mitsuketa!" << endl;
}
return 0;
}
/**************************************************************
Problem: 1033
User: 18434052
Language: C++
Result: 正确
Time:88 ms
Memory:2020 kb
****************************************************************/