uva 10479——The Hendrie Sequence
来源:互联网 发布:任意矩阵的零次幂 编辑:程序博客网 时间:2024/04/29 08:05
题意:开始一个数0,然后0变成1,后边的变换规则是如果当前是k就在后边加上k-1个0,然后再加上k-1,该问题求该序列的第n个数是多少。
思路:规律的题目。将串分成1,1,2,4,8,然后会发现s=1个s-2,2个s-3,3个s-4……然后n要用unsigned long long 。
code:
#include <bits/stdc++.h>using namespace std;typedef unsigned long long ull;int dfs(ull n,int p){ int q=1;ull k; for (int i=p-2;i>=0;i--){ if (i) k=1ll<<(i-1); else k=1; for (int j=0;j<q;j++){ if (k<n) n-=k; else return dfs(n,i); } q++; } return p;}int sol(ull n){ if (n==1) return 0;n--; for (int i=0;;i++){ ull t=1ll<<i; if (t<n) n-=t; else return dfs(n,i+1); }}int main(){ ull n; while (cin>>n&&n){ cout<<sol(n)<<endl; }}
0 0
- uva 10479——The Hendrie Sequence
- The Hendrie Sequence UVA
- UVA 10479 - The Hendrie Sequence(规律+递归)
- uva 10479 - The Hendrie Sequence(规律+递归)
- UVA 10479 The Hendrie Sequence 规律
- 习题 10-23 UVA - 10479 The Hendrie Sequence
- uva The Collatz Sequence
- UVa 694 - The Collatz Sequence
- uva-694 - The Collatz Sequence
- UVa 694 The Collatz Sequence
- UVA 694 - The Collatz Sequence
- UVA 694 - The Collatz Sequence
- UVa 694 - The Collatz Sequence
- UVA - 694 - The Collatz Sequence
- UVa 694 - The Collatz Sequence
- UVa 694 The Collatz Sequence
- UVA 694 The Collatz Sequence
- UVA 694 The Collatz Sequence
- UWP中用SplitView和Pivot实现两级目录
- iOS面试题4
- Chart控件使能光标(Cursor)
- C++入门学习笔记(三)--类的操作符重载
- CCS5.4常见编译错误与解决方案
- uva 10479——The Hendrie Sequence
- MySQL和Sql Server的sql语句区别
- loadlibrary 失败的解决方法
- Android开发中,activity生命周期说明
- android startActivityForResult和setResult用法解析
- 实用SQL语句大全
- CSR Audio Sink Application User Guide
- Android逆向工程-破解-哈皮妹-萝莉
- Eclipse+Android环境的搭建