lzy20091001 @ 2023-07-22 10:34:27
代码1,只过了1个点,我觉得这个反而应该快一点才对啊
测评信息
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, len;
string str;
cin >> str >> n;
len = str.length();
while (len < n)
len = len << 1;
while (n > str.length())
{
len = len >> 1;
if (n == len + 1)
n = len;
else
n = n - 1 - len;
}
cout << str[n - 1] << "\n";
return 0;
}
代码2,秒过
测评信息
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, len;
string str;
cin >> str >> n;
while (n > str.length())
{
len = str.length();
while (len < n)
len = (len << 1);
len = len >> 1;
if (n == len + 1)
n = len;
else
n = n - 1 - len;
}
cout << str[n - 1] << "\n";
return 0;
}
by lzy20091001 @ 2023-07-22 10:35:43
可以直接at我
by luminary3 @ 2023-07-22 10:42:09
by typerxiaozhu @ 2023-07-22 10:51:58
因为你两个代码逻辑不一样,第一份
by Bingxiu @ 2023-07-22 10:52:51
@lzy20091001 因为 while((len>>1)>=n) len = len >> 1;