求大佬debug

P3612 [USACO17JAN] Secret Cow Code S

wangderui111 @ 2024-01-14 17:38:26

#include<bits/stdc++.h>
using namespace std;
string fz(string a){
    string b;
    b+=a[a.length()-1];
    for(long long int i=0;i<a.length()-1;i++){
        b+=a[i];
    }
    return a+b;
}int main(){
    string c;
    cin>>c;
    long long int d;
    cin>>d;
    while(c.length()<d){
        c=fz(c);
    }cout<<c[d-1]<<endl;
    return 0;
}

敢问这道题怎么回事,为啥60分????


by wangderui111 @ 2024-01-14 17:42:54

搞错了,是40分,6个范例超时


by _8008008 @ 2024-01-14 18:48:22

时间复杂度错了吧


by wangderui111 @ 2024-01-20 20:32:14

看看p3817 讨论区里有题解 别说我水


by cat_lover1 @ 2024-01-22 13:22:19

可以参考下我这个蒟蒻的代码 大致思路就是每次都将字符串分成两部分,找到下面的字符和上面字符的对应关系

char c[31],ch;
long long t,l,rep,l1;
main(){
  while((ch=getchar())^' ')
    c[l++]=ch;
  scanf("%lld",&t),t--,l1=l;
  while(l<=t)l<<=1,++rep;
  while(rep--){
    if(t<l1)
      break;
    l>>=1,t==l?t--
    :t>l&&(t-=(1+l));
  }
  putchar(c[t]);
}

by wangderui111 @ 2024-02-19 10:22:25

谢谢大佬,我这题已经AC了,本评论结。


|