EOJ Monthly 2019.11 part solution to a problem

A title

Although this question is to sign the title, but the idea is very delicate, reminding me think about the future when you can consider the idea of ​​binary conversion

Since the length of this question requires an x-th word, but also noted that alternative words are the same, you can think of using k-ary transformed to think

I.e., the x-th request x-1 k-ary number, and then one by one according to the order before and after the traverse and the # alternative, it is noted, not to add 0

#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<cstdio>
#include <unordered_map>
using namespace std;
const int N=2000005;
const int inf=0x3f3f3f3f;
typedef long long ll;
vector<int> num;
vector<char> c;
int main(){
    int n,m,k;
    ll x;
    string s;
    cin>>n>>m>>k>>x;
    char t;
    cin>>s;
    int i,j;
    x-=1;
    while(x){
        num.push_back(x%k);
        x/=k;
    }
    int mid=m-(int)num.size();
    for(i=0;i<mid;i++)
    num.push_back(0);
    m-=1;
    for(i=0;i<n;i++){
        if(s[i]=='#'){
            for(j=0;j<k;j++){
                cin>>t;
                c.push_back(t);
            }
            sort(c.begin(),c.end());
            cout<<c[num[m]]; 
            m--;
            c.clear();
        }
        else
        cout<<s[i];
    }
    cout<<endl;
}
View Code

Guess you like

Origin www.cnblogs.com/ctyakwf/p/12189181.html