Uva--1262(数学,排列)

2014-09-03 13:29:33

题目老长:放链接

思路:直接模拟。

 1 /*************************************************************************
 2     > File Name: Uva1262.cpp
 3     > Author: Nature
 4     > Mail: 564374850@qq.com
 5     > Created Time: Wed 03 Sep 2014 12:35:16 PM CST
 6 ************************************************************************/
 7 
 8 #include <cstdio>
 9 #include <cstring>
10 #include <cstdlib>
11 #include <cmath>
12 #include <vector>
13 #include <iostream>
14 #include <algorithm>
15 using namespace std;
16 
17 int Case,k,used[10][30];
18 char g1[10][10],g2[10][10],ans[10];
19 vector<int> ver[10];
20 int num[10];
21 
22 int main(){
23     //freopen("in","r",stdin);
24     scanf("%d",&Case);
25     while(Case--){
26         memset(used,0,sizeof(used));
27         memset(ans,0,sizeof(ans));
28         for(int i = 0; i < 5; ++i) ver[i].clear();
29         num[5] = 1;
30         scanf("%d",&k);
31         for(int i = 0; i < 6; ++i) scanf("%s",g1[i]);
32         for(int i = 0; i < 6; ++i) scanf("%s",g2[i]);
33         for(int i = 4; i >= 0; --i){
34             for(int j = 0; j < 6; ++j){
35                 int id = g1[j][i] - 'A';
36                 used[i][id] = 1;
37             }
38             for(int j = 0; j < 6; ++j){
39                 int id = g2[j][i] - 'A';
40                 if(used[i][id]){
41                     ver[i].push_back(id);
42                     used[i][id] = 0;
43                 }
44             }
45             sort(ver[i].begin(),ver[i].end());
46             num[i] = ver[i].size();
47             num[i] *= num[i + 1];
48         }
49         int flag = 1;
50         for(int i = 0; i < 5; ++i){
51             int len = ver[i].size();
52             for(int j = 0; j < len; ++j){
53                 if(num[i + 1] * (j + 1) >= k){
54                     ans[i] = ver[i][j] + 'A';
55                     k -= num[i + 1] * j;
56                     break;
57                 }
58             }
59             if(ans[i] == 0){
60                 flag = 0;
61                 break;
62             }
63         }
64         if(flag) printf("%s\n",ans);
65         else printf("NO\n");
66     }
67     return 0;
68 }

 

posted @ 2014-09-03 13:33  Naturain  阅读(196)  评论(0编辑  收藏  举报