Problem
https://codeforces.com/problemset/problem/1620/C
Solution
To solve the problem,we have to bear one thing in mind:a series of asterisks has to be considered as a whole.
So we come to the easier part.Starting from the end of the original string,we find that a series of t1 asterisks has t1*k+1 possibilities of "b"s and we only have to calculate how many "b"s a series of asterisks means.
It's quite like a number game.For example: **a***,k=3,x=20------》7|10 and x-1=19-------》19=10*1+9---------》babbbbbbbbb.
So Ac code is:
#include<bits/stdc++.h> using namespace std; #define N 200005 #define mp make_pair #define ll long long ll t; ll n,k,x; //void test(string s) { // getchar(); // reverse(s.begin(),s.end()); // cout<<s<<endl; //} int main() { cin>>t; while(t--) { string s; cin>>n>>k>>x; cin>>s; x--; reverse(s.begin(),s.end()); ll point = 0; while(point<s.length()) { if(s[point]=='*') { ll num = 0; ll st = point; while(s[point]=='*') { num++; point++; } ll en = point; string s1 = ""; ll mod = num*k+1; for(ll i=1; i<=x%mod; i++) { s1.append("b"); } s = s.substr(0,st-0)+s1+s.substr(en,s.length()-en); point = st+s1.length(); x/=mod; } else { point++; } } reverse(s.begin(),s.end()); string s1=""; ll p=0; while(p<s.length()) { if(s[p]=='*') p++; else s1+=s[p++]; } cout<<s1<<endl; } return 0; }