uva1262

时间:2023-03-08 20:05:33
                           /*  解码 _________________________________________________________________________________

                               #include <iostream>
#include <map>
#include <cmath>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
#define fir first
#define sec second
#define pb(x) push_back(x)
#define mem(A, X) memset(A, X, sizeof A)
#define REP(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define rep(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))
#define foreach(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e)
typedef long long LL;
typedef unsigned long long ull;
typedef pair<long,long> pll; LL T,n;
int k;
const int mod=1e9+7;
const int maxn=1e5+10;
char s[2][6][10],ans[10];
int cnt;
bool dfs(int col)
{
if(col==5)
{
if(++cnt==k)
{
ans[5]='\0';
printf("%s\n",ans);
return true;
}
else
return false;
}
else
{
bool vis[2][26];
mem(vis,false); REP(i,0,1)
REP(j,0,5)
vis[i][ s[i][j][col]-'A' ]=true; //只处理当前列对应的可能位置,搜索时只处理当前层。 REP(j,0,25)
if(vis[0][j]==true && vis[1][j]==true)
{
ans[col]=j+'A';
if( dfs(col+1) ) return true;
}
}
return false; } int main()
{
freopen("in.txt","r",stdin);
//while(cin>>n)
while(scanf("%d",&T)!=EOF)
{
REP(kase,1,T)
{
scanf("%d",&k);
REP(i,0,1)
REP(j,0,5)
{
scanf("%s",&s[i][j]);
//printf("%s\n",s[i][j]);
}
cnt=0;
if(!dfs(0)) puts("NO");
} }
return 0;
} /*
note : 编码理论
本题运用的暴力方法,编写简单,
如果用直接构造性的编码,实现时要注意更多的细节。 debug :
optimize:
直接操纵输入的字符,减少中间的传递,简化过程。
二维的数组字母表,处理多个相似的对象时进行优化。
*/