题目
分析
其实就是 K K K进制凑数,类比 10 10 10进制的,乱搞即可。
题目
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
int read(){
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
return x*f;
}
#define MAXK 26
#define MAXN 500
#define MAXM MAXN
int N,M,K,X,cnt;
int A[MAXM+5],pos[MAXN+5];
char str[MAXN+5],L[MAXM+5][MAXK+5];
int main(){
freopen("tavan.in" ,"r", stdin);
freopen("tavan.out","w",stdout);
N=read(),M=read(),K=read(),X=read()-1;
scanf("%s",str+1);
for(int i=1;i<=N;i++)
if(str[i]=='#')
pos[cnt++]=i;
for(int i=0;i<M;i++){
scanf("%s",L[i]);
sort(L[i],L[i]+K);//要排序
}
cnt=0;
long long P=1ll;//P是位值
while(P*K<=X)
P*=K,cnt++;//找位数
while(X&&cnt>=0){
A[cnt]=X/P;//从左至右的第cnt位
X-=A[cnt--]*P;
P/=K;//位值从大至小
}
for(int i=0;i<M;i++)
str[pos[i]]=L[i][A[M-i-1]];
puts(str+1);
}