40pts 求助!

P3612 [USACO17JAN] Secret Cow Code S

zjr0330 @ 2023-02-21 18:07:01

1、3、4、5AC,其他全MLE

#include<bits/stdc++.h>
using namespace std;
int main() {
    string s;
    string sn = s;
    char ss;
    cin >> s;
    long long n,i = 1;
    cin >> n;
    long long len = s.size();
//  cout << len << endl;
    while (n >= len) {
        sn=s;
//      cout << len << endl;
        for (i = 1; i <= len; i++) {
            if (i == 1) {
                ss = sn[i];
                swap(sn[0],sn[i]);
            } else if (i == len) {
                swap(ss, sn[0]);
            } else {
                swap(ss, sn[i]);
            }
        }
        s += sn;
        len = s.size();
//      cout << s << endl;
    }
//  cout << s << endl;
    cout << s[n - 1] << endl;
    return 0;
}

by vzcx_host @ 2023-02-21 18:15:03

让你暴力做,你也太暴力了


by zjr0330 @ 2023-02-21 18:31:09

@Industrial_banana 不会做啊。。。。。。也就只会暴力

有句俗话说得好:偏分过样例,暴力出奇迹


by GeorgeAAAADHD @ 2023-02-21 21:36:28


by GeorgeAAAADHD @ 2023-02-21 21:36:54

明显是递推。


by Zhouwenxuan @ 2023-02-21 21:54:47


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

by Zhouwenxuan @ 2023-02-21 21:55:25

别看了,40分。


by zjr0330 @ 2023-02-21 21:59:31

@Zhouwenxuan ......


by zjr0330 @ 2023-02-21 21:59:59

@GeorgeAAAADHD 谢谢!


|