Password UVA

来源:互联网 发布:网络文化节上的讲话 编辑:程序博客网 时间:2024/06/05 06:48

题目传送门

题意;给你两个6行5列的密码矩阵,找出满足下列条件的“密码”:密码中的每一个字母都在两个矩阵的对应列中出现,求字典序第k大的的密码,如果没有输出NO。

题意:直接暴力瞎搞一下就好了。

#include <algorithm>#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <list>#include <map>#include <queue>#include <set>#include <stack>#include <string>#include <vector>#define MAXN 10#define MAXE 400#define INF 100000000#define MOD 10001#define LL long long#define pi 3.14159using namespace std;string matrix1[MAXN];string matrix2[MAXN];set<char> Set[MAXN];int main() {    std::ios::sync_with_stdio(false);    int T;    cin >> T;    for (int kase = 1; kase <= T; ++kase) {        int k;        for (int i = 0; i < MAXN; ++i) {            Set[i].clear();        }        cin >> k;        for (int i = 0; i < 6; ++i) {            cin >> matrix1[i];        }        for (int i = 0; i < 6; ++i) {            cin >> matrix2[i];        }        set<char> s;        for (int i = 0; i < 5; ++i) {            s.clear();            for (int j = 0; j < 6; ++j) {                s.insert(matrix1[j][i]);            }            for (int j = 0; j < 6; ++j) {                if (s.count(matrix2[j][i])) {                    Set[i].insert(matrix2[j][i]);                }            }        }        if (Set[0].size() * Set[1].size() * Set[2].size() * Set[3].size() * Set[4].size() < k) {            cout << "NO\n";        } else {            int num1 = (int) Set[1].size();            int num2 = (int) Set[2].size();            int num3 = (int) Set[3].size();            int num4 = (int) Set[4].size();            vector<int> vec;            int pos = k / (num1 * num2 * num3 * num4);            k %= (num1 * num2 * num3 * num4);            if (k == 0) {                vec.push_back(pos - 1);                k = num1 * num2 * num3 * num4;            } else {                vec.push_back(pos);            }            pos = k / (num2 * num3 * num4);            k %= (num2 * num3 * num4);            if (k == 0) {                vec.push_back(pos - 1);                k = num2 * num3 * num4;            } else {                vec.push_back(pos);            }            pos = k / (num3 * num4);            k %= (num3 * num4);            if (k == 0) {                vec.push_back(pos - 1);                k = num3 * num4;            } else {                vec.push_back(pos);            }            pos = k / num4;            k %= num4;            if (k == 0) {                vec.push_back(pos - 1);                k = num4;            } else {                vec.push_back(pos);            }            pos = k;            vec.push_back(pos - 1);            string str = "\0";            for (int i = 0; i < 5; ++i) {                int ans = 0;                for (set<char>::iterator it = Set[i].begin(); it != Set[i].end(); ++it) {                    if (ans == vec[i]) {                        str += *it;                        break;                    }                    ans++;                }            }            cout << str << endl;        }    }    return 0;}/* 3 1 AYGSU DOMRA CPFAS XBODG WDYPK PRXWO CBOPT DOSBG GTRAR APMMS WSXNU EFGHI 5 AYGSU DOMRA CPFAS XBODG WDYPK PRXWO CBOPT DOSBG GTRAR APMMS WSXNU EFGHI 64 FGHIJ EFGHI DEFGH CDEFG BCDEF ABCDE WBXDY UWYXZ XXZFG YYFYH EZWZI ZGHIJ */
原创粉丝点击