UVa12478 - Hardest Problem Ever (枚举)

简介: UVa12478 - Hardest Problem Ever (枚举)
#include <cstdio>#include <string>#include <algorithm>usingnamespacestd;
constintN=9;
chartable[N][N] = {
                       {'O', 'B', 'I', 'D', 'A', 'I', 'B', 'K', 'R'},
                       {'R', 'K', 'A', 'U', 'L', 'H', 'I', 'S', 'P'},
                       {'S', 'A', 'D', 'I', 'Y', 'A', 'N', 'N', 'O'},
                       {'H', 'E', 'I', 'S', 'A', 'W', 'H', 'I', 'A'},
                       {'I', 'R', 'A', 'K', 'I', 'B', 'U', 'L', 'S'},
                       {'M', 'F', 'B', 'I', 'N', 'T', 'R', 'N', 'O'},
                       {'U', 'T', 'O', 'Y', 'Z', 'I', 'F', 'A', 'H'},
                       {'L', 'E', 'B', 'S', 'Y', 'N', 'U', 'N', 'E'},
                       {'E', 'M', 'O', 'T', 'I', 'O', 'N', 'A', 'L'}
                       };
stringstr[8] = {"RAKIBUL", "ANINDYA", "MOSHIUR", "SHIPLU", "KABIR", "SUNNY", "OBAIDA", "WASI"};
intmain()
{
for (inti=0; i<8; i++) {
stringstrtmp=str[i];
sort(strtmp.begin(), strtmp.end());
intlen=str[i].length();
intcnt=0;
for (intj=0; j<N; j++) {
stringtmp;
for (intk=0; k+len<=N; k++) {
tmp.clear();
for (intm=0; m<len; m++) {
tmp.append(1, table[j][k+m]);
                }
sort(tmp.begin(), tmp.end());
if (tmp==strtmp) cnt++;
            }
        }
for (intj=0; j<N; j++) {
stringtmp;
for (intk=0; k+len<=N; k++) {
tmp.clear();
for (intm=0; m<len; m++) {
tmp.append(1, table[k+m][j]);
                }
sort(tmp.begin(), tmp.end());
if (tmp==strtmp) cnt++;
            }
        }
if (cnt==2) printf("%s\n", str[i].c_str());
    }
return0;
}
目录
相关文章
UVa1531 - Problem Bee
UVa1531 - Problem Bee
51 0
UVa11296 - Counting Solutions to an Integral Equation(枚举技巧)
UVa11296 - Counting Solutions to an Integral Equation(枚举技巧)
49 0
UVa11565 - Simple Equations
UVa11565 - Simple Equations
52 0
A. Codeforces Checking(打表枚举)
A. Codeforces Checking(打表枚举)
52 0
HDU-1048,The Hardest Problem Ever(字符串处理)
HDU-1048,The Hardest Problem Ever(字符串处理)
HDOJ/HDU 1015 Safecracker(枚举)
HDOJ/HDU 1015 Safecracker(枚举)
109 0
LeetCode---Problem6 ZigZag Conversion
ZigZag问题思路。代码整洁并不一定执行速度就好~
789 0