90分求调T_T
查看原帖
90分求调T_T
1501687
LioHein楼主2024/12/16 18:33
#include <iostream>
#include <cmath>
#include <string>
using namespace std;

long long N;

int main()
{
    long long index = 0,res=0;
    string a;
    cin >> a >> N;
    int l = a.length();
    a = " " + a;
    if(N<=l) index = -1;
    else
        while( !( (l * pow(2, index)) <= N && N <= l * pow(2, index + 1) ) )
        index++;
    //如果N不在范围内,则index递增,直到N属于范围内

    //原始代码
    /*for(int i=0;i<=index;i++)
        for(int j =l+1 ;j <= l * pow(2, i+1) ; j++){
            if(j == l*pow(2,i) + 1)a[j] = a[j-1];
            else a[j] = a[j - l * pow(2, i) - 1];
        }*/

    //优化后:
        res=N;
        long long j;
    for(int i=index;i>=0;i--){
        if( (l * pow(2, i)) <= res && res <= l * pow(2, i + 1) )
        for(j = res ;j >= l * pow(2, i) ; ){
            if(j == l*pow(2,i) + 1) {j = j - 1;break;}
            else j = (j - l * p ow(2, i) - 1);
            //cout<<'1'<<' '<<j<<endl;检查
        }
        else continue;
        cout<<i<<' '<<j<<endl;
        res = j;
        if(res<=l)break;
    }
    int ans = res;
    cout<<a[ans];
    return 0;
}

第32行改为int 就能过第二个,但是现在只错第二个,闷了真不知道咋改。 蒟蒻躲在角落里等犇犇来救T_T

2024/12/16 18:33
加载中...