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. /lib64和/usr/lib64和/usr/local/lib64的区别

    简单说,/lib64是内核级的,/usr/lib64是系统级的,/usr/local/lib64是用户级的. /lib/ — 包含许多被 /bin/ 和 /sbin/ 中的程序使用的库文件.目录 /u ...

  2. Camera Calibration 相机标定:原理简介(四)

    4 基于3D标定物的标定方法 使用基于3D标定物进行相机标定,是一种传统且常见的相机标定法.3D标定物在不同应用场景下不尽相同,摄影测量学中,使用的3D标定物种类最为繁杂,如图-1的室内控制场,由多条 ...

  3. 洛谷 P3147 [USACO16OPEN]262144

    P3147 [USACO16OPEN]262144 题目描述 Bessie likes downloading games to play on her cell phone, even though ...

  4. Unix发展史

    简述 了解过去,我们才能知其然,更知所以然.总结过去,我们才会知道明天该何去何从.在时间的滚轮中,许许多多的东西就像流星一样一闪而逝,而有些东西却能经受着时间的考验散发着经久的魅力,让人津津乐道.流传 ...

  5. Qt之图形(简笔画-绘制漂亮的西瓜)

    简述 Summer is coming-我们呢,为大家准备了丰盛的佳果-西瓜,清爽解渴,甘味多汁. 一笔一划学简笔画,分分钟让你掌握一门新技能,下面我们来绘制一个"盛夏之王"-西瓜 ...

  6. php通过shell调用Hadoop的方法

    1.php代码(index.php) <!DOCTYPE html> <html> <!-- <style> body{background-color:re ...

  7. Unity 内置Shader变量、辅助函数等

    一:标准库里的常用.cginc文件 HLSLSupport.cginc - (automatically included) Helper macros and definitions for cro ...

  8. Nginx搭建图片服务器

    Nginx搭建图片服务器 标签(空格分隔): linux,nginx Nginx常用命令 ./nginx 启动 ./nginx -s reload 重载配置文件 ./nginx -s stop|sta ...

  9. Git放弃本地更改恢复到资源库版本

    使用git版本控制工具在本地clone一份代码后,如果发现修改错误想恢复到资源库版本,下面两行可以轻松加愉快的搞定: git clean -xdf git checkout -f git的更多详细用法 ...

  10. js控制分页打印、打印分页示例

    1 打印分页 需要添加一段代码 <div  style="page-break-before:always;"><br /></div> 2 & ...