P1176奇怪的数列

背景

一天。学军数学小组的成员遇到了一个奇怪的数列,正巧信息小组的你碰到了他们。

于是他们把这个数列展示给你……

描写叙述

这个数列是这种:

0,1,3,2,6,7,5,4,12,13,15,14,10,11,9,8,24,25,27,26,30,31……

先细致研究一下这个数列的规律。

如今他们请你编写一个程序,要求找出数n在此数列中的位置序号k。

格式

输入格式

输入数据仅仅有一行,为数 n (n<=2^31-1)

输出格式

输出数据仅仅有一行,为数k。

例子1

例子输入1[复制]

5

例子输出1[复制]

7

限制

时限:1s

来源

From chnlkw,wlfish

a(n) = if n<2 then n else 2*m + (n mod 2 + m mod 2) mod 2, with m=a(floor(n/2)).

#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm> using namespace std; #define pb push_back
#define mp make_pair
#define fillchar(a, x) memset(a, x, sizeof(a))
#define copy(a, b) memcpy(a, b, sizeof(a))
#define S_queue<P> priority_queue<P, vector<P>,greater<P> > typedef long long LL;
typedef pair<int, int > PII;
typedef unsigned long long uLL;
template<typename T>
void print(T* p, T* q, string Gap = " "){int d = p < q ? 1 : -1;while(p != q){cout << *p;p += d;if(p != q) cout << Gap; }cout << endl;}
template<typename T>
void print(const T &a, string bes = "") {int len = bes.length();if(len >= 2)cout << bes[0] << a << bes[1] << endl;else cout << a << endl;} const int INF = 0x3f3f3f3f;
const int MAXM = 1e6 + 5;
const int MAXN = 1e4 + 5; uLL fun(uLL x){
if(x < 2) return x;
else{
uLL m = fun(floor(x / 2));
return 2 * m + (x % 2 + m % 2) % 2;
}
} int main(){
uLL n;
//freopen("D://out.txt","w",stdout);
scanf("%I64d", &n);
print(fun(n) + 1);
}

vijos - P1176奇怪的数列 (递归 + 找规律)的更多相关文章

  1. 【hdu 6172】Array Challenge(数列、找规律)

    多校10 1002 HDU 6172 Array Challenge 题意 There's an array that is generated by following rule. \(h_0=2, ...

  2. vijos - P1447开关灯泡 (大数模板 + 找规律 + 全然数 + python)

    P1447开关灯泡 Accepted 标签:CSC WorkGroup III[显示标签] 描写叙述 一个房间里有n盏灯泡.一開始都是熄着的,有1到n个时刻.每一个时刻i,我们会将i的倍数的灯泡改变状 ...

  3. HDU 4639 Hehe(字符串处理,斐波纳契数列,找规律)

    题目 //每次for循环的时候总是会忘记最后一段,真是白痴.... //连续的he的个数 种数 //0 1 //1 1 //2 2 //3 3 //4 5 //5 8 //…… …… //斐波纳契数列 ...

  4. Fibonacci数列(找规律)

    题目描述 Fibonacci数列是这样定义的:F[0] = 0F[1] = 1for each i ≥ 2: F[i] = F[i-1] + F[i-2]因此,Fibonacci数列就形如:0, 1, ...

  5. hdu4639 hehe ——斐波纳契数列,找规律

    link:http://acm.hdu.edu.cn/showproblem.php?pid=4639 refer to: http://blog.csdn.net/dongdongzhang_/ar ...

  6. C基础之递归(思想很重要,学会找规律)

    递归思想的条件:1.函数自己调用自己 2.函数必须有一个固定的返回值(如果没有这个条件会发生死循环) ----规律很重要 简单递归题目一: 设计一个函数计算一个整数的n次方,比如2的3次方,就是8 步 ...

  7. CodeForces 450B Jzzhu and Sequences 费波纳茨数列+找规律+负数MOD

    题目:Click here 题意:给定数列满足求f(n)mod(1e9+7). 分析:规律题,找规律,特别注意负数取mod. #include <iostream> #include &l ...

  8. [Swust OJ 666]--初来乍到(题号都这么溜~~,递归,找规律)

    题目链接:http://acm.swust.edu.cn/problem/0666/ Time limit(ms): 1000 Memory limit(kb): 65535   Descriptio ...

  9. HDU 1165 Eddy's research II(给出递归公式,然后找规律)

    - Eddy's research II Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. js 监听ios手机键盘弹起和收起的事件

    document.body.addEventListener('focusin', () => { //软键盘弹起事件 console.log("键盘弹起") }) docu ...

  2. 【codeforces 196B】Infinite Maze

    [题目链接]:http://codeforces.com/problemset/problem/196/B [题意] 给你一个n*m的棋盘; 然后你能够无限复制这个棋盘; 在这个棋盘上你有一个起点s; ...

  3. Git学习总结(7)——Git GUI学习教程

    前言 之前一直想一篇这样的东西,因为最初接触时,我也认真看了廖雪峰的教程,但是似乎我觉得讲得有点多,而且还是会给我带来很多多余且重复的操作负担,所以我希望能压缩一下它在我工作中的成本,但是搜索了一下并 ...

  4. Android Camera子系统之Linux C应用开发人员View

    Android Camera HAL通过V4L2接口与内核Camera Driver交互.本文从Linux应用开发人员的角度审视Android Camera子系统. V4L2应用开发一般流程: 1. ...

  5. video : Write and Submit your first Linux kernel Patch

    http://v.youku.com/v_show/id_XNDMwNzc3MTI4.html After working with Linux (mostly as an advanced user ...

  6. codeforces #313(div 2)

    B. Gerald is into Art time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  7. m_Orchestrate learning system---二十五、复制类的时候最容易出现的错误是什么

    m_Orchestrate learning system---二十五.复制类的时候最容易出现的错误是什么 一.总结 一句话总结:命名空间错误导致Analyze类虽然继承了Base类,但是没有执行里面 ...

  8. php中file_get_contents如何读取大容量文件

    php中file_get_contents如何读取大容量文件 一.总结 一句话总结:使用file_get_contents()进行分段读取,file_get_contents()函数可以分段读取 1. ...

  9. python 统计文件top IP

    lines = ''' 1.2.2.3 1.21.29.19.... ''' cnt = {} for line in lines.split(): if line not in cnt: cnt[l ...

  10. django 笔记5 外键 ForeignKey

    class UsserGroup(models.Model): uid = models.AutoField(primary_key=True) caption = models.CharField( ...