Topic:
Give you two 6-Row 5-column alphabets, an integer K. the same letter in column i of the two tables may be the letter in the i of the password. Rank all possibilities in ascending order, and find out what the possible password in the k after finishing the order. If there is no output No.
Train of thought:
Simulation... The stored array is traversed by columns, then stored in the vector, sorted by sort, unique de duplicated, and then the position in the vector is calculated according to the suffix product.
See code for details
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <cstring> using namespace std; typedef long long ll; char a[10][10],b[10][10]; vector<char>x[10]; int ans[10],h[10]; int main() { int t,n; //FILE *fp; //fp=fopen("DATA.txt", "w"); scanf("%d",&t); while(t--) { int flag=0; for(int i=0;i<5;i++) x[i].clear(); memset(ans,0,sizeof(ans)); memset(h,0,sizeof(h)); scanf("%d",&n); for(int i=0;i<6;i++) scanf("%s",a[i]); for(int i=0;i<6;i++) scanf("%s",b[i]); for(int i=0;i<5;i++){ for(int j=0;j<6;j++){ for(int k=0;k<6;k++){ if(a[j][i]==b[k][i]) //Traversal by column x[i].push_back(a[j][i]); } } } for(int i=0;i<5;i++){ sort(x[i].begin(),x[i].end()); //sort unique(x[i].begin(),x[i].end()); //Duplicate removal if(x[i].empty()) //Judge whether it is empty { flag=1; break; } while(ans[i]<x[i].size()-1&&x[i][ans[i]+1]>x[i][ans[i]]) //Because unique de duplication is to change the repetitive into the non repetitive ans[i]++; ans[i]++; //Because at least one //printf("%d\n",ans[i]); } if(flag) //Note this when judging whether the vector array is empty { printf("NO\n"); continue; } h[5]=1; for(int i=4;i>=0;i--){ h[i]=1; h[i]=ans[i]*h[i+1]; //Suffix product } if(n>h[0]) //Judge whether the limit is exceeded printf("NO\n"); else{ n--; for(int i=0;i<5;i++){ printf("%c",x[i][n/h[i+1]]); //Seek location n%=h[i+1]; } printf("\n"); } } return 0; }