40分求调,P3612

P3612 [USACO17JAN] Secret Cow Code S

BillWan1201 @ 2024-10-14 18:38:12

40分求调,其他点MLE了

#include<bits/stdc++.h>
#include<string> 
using namespace std;
int main(){
    string s;
    cin>>s;
    long long n;
    cin>>n;
    string t="";
    long long len=s.size();
    while(len<n){
        t=s.substr(0,len-1);
        s+=string(1,s[len-1]);
        s+=t;
        len=s.size();
    }
    cout<<s[n-1];
    return 0;
}

by Lots_of @ 2024-10-14 18:41:43

@BillWan1201 首先,用了 bits 为什么还要其他的头文件


by BillWan1201 @ 2024-10-14 18:51:11

那也不影响啊


by wxc0714 @ 2024-12-08 16:26:47

@BillWan1201

#include <bits/stdc++.h>
using namespace std;
string s;
long long n,l;
char f(long long len,long long n){
    if(len<=l) return s[n];
    long long mid=len/2;
    if(n<=mid)          
        return f(mid,n);
    n-=mid;
    if(n==1) return f(mid,mid);  
    return f(mid,n-1);  
}
int main(){
    cin>>s>>n;
    long long len=s.size();
    l=len;
    s=' '+s;
    while(len<n) len*=2;
    cout<<f(len,n);
    return 0;
}

关注一下吧QAQ


by BillWan1201 @ 2024-12-08 18:30:02

@wxc0714 多谢!已关注


by wxc0714 @ 2024-12-09 20:20:55

已互关


|