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
56 0
UVa11296 - Counting Solutions to an Integral Equation(枚举技巧)
UVa11296 - Counting Solutions to an Integral Equation(枚举技巧)
52 0
uva101 The Blocks Problem
uva101 The Blocks Problem
58 0
uva673 Parentheses Balance
uva673 Parentheses Balance
49 0
HDOJ1002题A + B Problem II,2个大数相加
HDOJ1002题A + B Problem II,2个大数相加
120 0