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;
}
#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;
}
相关文章推荐
- uva 10479 - The Hendrie Sequence(规律+递归)
- UVA 10479 The Hendrie Sequence 规律
- UVA 10479 - The Hendrie Sequence(规律+递归)
- UVA 10479 The Hendrie Sequence
- uva 10479——The Hendrie Sequence
- UVA-10689 Yet another Number Sequence (矩阵二分幂模板)
- UVA 694-The Collatz Sequence
- 【矩阵快速幂】UVA 10698 G - Yet another Number Sequence
- UVA 1406 - A Sequence of Numbers(树状数组)
- uva 10689 - Yet another Number Sequence(矩阵快速幂)
- UVA 348 Optimal Array Multiplication Sequence
- UVA 10689 Yet another Number Sequence(矩阵快速幂求Fib数列)
- UVa348 - Optimal Array Multiplication Sequence
- UVA 694-The Collatz Sequence
- UVa 348 Optimal Array Multiplication Sequence
- uva 10479(找规律+递归)
- 环状序列(Circular Sequence, ACM/ICPC Seoul 2004, UVa1584)
- UVa 348 - Optimal Array Multiplication Sequence
- UVA 10698 Yet another Number Sequence 矩阵快速幂
- Yet another Number Sequence UVA - 10689 (矩阵快速幂)