AcWing 1799. 奶牛密码
原题链接
简单
作者:
@-_-@
,
2024-04-22 16:41:33
,
所有人可见
,
阅读 5
/*
需要直到N位置的字符在原字符串中所在的位置即可
如果有长度是n的字符串复制拼接,设第i个字符是f(i),那么有递推式
f(i + 1) = f(i) - L/2 L是f(i)时刻字符串的长度
本题中,需要先把最后一个字符移到最前面再复制拼接
则 f(i + 1) = f(i) - 1 - L/2
递归/递推
*/
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 40;
string s;
LL n;
LL temp;
int main()
{
cin >> s >> n;
LL len = s.size();
while (len < n)
{
temp = len;
while (n > temp) temp *= 2;
temp /= 2;
n -= (temp + 1);
if (n == 0) n = temp;
}
cout << s[n - 1] << endl;
return 0;
}