vijos - 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。
限制
时限: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)).
GEDC$S$~6RL7A)W[8QFYP.png)
#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奇怪的数列 (递归 + 找规律)的更多相关文章
- 【hdu 6172】Array Challenge(数列、找规律)
多校10 1002 HDU 6172 Array Challenge 题意 There's an array that is generated by following rule. \(h_0=2, ...
- vijos - P1447开关灯泡 (大数模板 + 找规律 + 全然数 + python)
P1447开关灯泡 Accepted 标签:CSC WorkGroup III[显示标签] 描写叙述 一个房间里有n盏灯泡.一開始都是熄着的,有1到n个时刻.每一个时刻i,我们会将i的倍数的灯泡改变状 ...
- HDU 4639 Hehe(字符串处理,斐波纳契数列,找规律)
题目 //每次for循环的时候总是会忘记最后一段,真是白痴.... //连续的he的个数 种数 //0 1 //1 1 //2 2 //3 3 //4 5 //5 8 //…… …… //斐波纳契数列 ...
- Fibonacci数列(找规律)
题目描述 Fibonacci数列是这样定义的:F[0] = 0F[1] = 1for each i ≥ 2: F[i] = F[i-1] + F[i-2]因此,Fibonacci数列就形如:0, 1, ...
- hdu4639 hehe ——斐波纳契数列,找规律
link:http://acm.hdu.edu.cn/showproblem.php?pid=4639 refer to: http://blog.csdn.net/dongdongzhang_/ar ...
- C基础之递归(思想很重要,学会找规律)
递归思想的条件:1.函数自己调用自己 2.函数必须有一个固定的返回值(如果没有这个条件会发生死循环) ----规律很重要 简单递归题目一: 设计一个函数计算一个整数的n次方,比如2的3次方,就是8 步 ...
- CodeForces 450B Jzzhu and Sequences 费波纳茨数列+找规律+负数MOD
题目:Click here 题意:给定数列满足求f(n)mod(1e9+7). 分析:规律题,找规律,特别注意负数取mod. #include <iostream> #include &l ...
- [Swust OJ 666]--初来乍到(题号都这么溜~~,递归,找规律)
题目链接:http://acm.swust.edu.cn/problem/0666/ Time limit(ms): 1000 Memory limit(kb): 65535 Descriptio ...
- HDU 1165 Eddy's research II(给出递归公式,然后找规律)
- Eddy's research II Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- win10 无法访问XP 共享目录原因
win10 无法访问XP 共享目录原因 *现象: 在地址栏中输入\\192.168.100.5 (XP文件服务器),出现:.....找不到网络路径, 此连接尚未还原. ...
- 多任务-进程之Queue的进程间通信
1.经过线程和进程的对比,不难的知道,线程和进程有相当大的区别,如全局变量资源不能够共享. 2.在不同的进程间,如何实现通信呢? 需要提及的一个概念就是Queue,它是一个消息队列,下面通过一个例子来 ...
- 模块 -logging
模块 -logging 一:在控制台显示:默认 import logging logging.debug("debug") logging.info("debug&quo ...
- 模块 –SYS
模块 –SYS os模块是跟操作系统的交互 sys是跟python解释器的交互 sys.argv 命令行参数List,第一个元素是程序本身路径 返回一个列表 In [218]: sys.argv Ou ...
- PHP XML操作类DOMDocument
不得不自已写一个.XML 的操作一直没有用过.下面是自己搜集的XML操作类 DOMDocument相关的内容. 属性: Attributes 存储节点的属性列表(只读) childNodes 存储节点 ...
- HDU-1215 七夕节 数论 唯一分解定理 求约数之和
题目链接:https://cn.vjudge.net/problem/HDU-1215 题意 中文题,自己去看吧,懒得写:) 思路 \[ Ans=\prod \sum p_i^j \] 唯一分解定理 ...
- C++容器(五):set类型
set类型 map容器是键-值对的集合,好比以任命为键的地址和电话号码.而set容器只是单纯的键的集合.当只想知道一个值是否存在时,使用set容器是最适合. 使用set容器必须包含set头文件: #i ...
- 将Spring Boot应用程序迁移到Java9:兼容性
将 Spring Boot 应用程序迁移到 Java 9:兼容性 随着 Java 9 的到来,关于如何迁移应用程序以使用模块系统有很多的讨论.遗憾的是,大多数文章的焦点都集中于简单的 Hello Wo ...
- [MST] Create Dynamic Types and use Type Composition to Extract Common Functionality
Since MST offers a runtime type system, it can create and compose types on the fly, making it possib ...
- ACM POJ 1146 ID Codes
题目大意:输入一个字符串.输出它的下一个字典序排列. 字典序算法思想: 1.从右向左寻找字符串找出第一个a[i]<a[i+1]的位置i; 2.从右向左找出第一个大于a[i]的元素a[j]; 3. ...