您的位置:首页 > 产品设计 > UI/UE

The Hendrie Sequence UVA - 10479

2017-11-16 17:08 148 查看
参考别人的博客,可以按照1,2,4,8......的形式将这些串分割开,然后对于输入的n,首先进行大致地定位,然后对于定位到的串s中,那么s就有1个s-2的串,2个s-3的串,以此类推,直到最后以s自己结尾,然后逐步判断即可,具体实现见如下代码:

#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<deque>
#include<functional>
using namespace std;

typedef unsigned long long uLL;

uLL n;

uLL find_res(int aim){
int amount = 1;
for (int i = aim - 2; i >= 0;i--){
uLL s = i ? (1uLL << (i - 1)) : 1uLL;
for (int k = 0; k < amount; k++){
if (n > s) n -= s;
else return find_res(i);
}
amount++;
}
return aim;
}

int main(){
while (cin >> n&&n){
if (n == 1) cout << "0\n";
else{
n--;
int res;
for (uLL i = 1;; i++){
uLL temp = 1uLL << (i-1);
if (n > temp) n -= temp;
else{
res = find_res(i);
break;
}
}
cout << res << endl;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: