Light oj 1105 - Fi Binary Number(计数)
来源:互联网 发布:单片机程序流程图画法 编辑:程序博客网 时间:2024/05/18 18:45
1105 - Fi Binary Number
PDF (English)StatisticsForum
Time Limit: 2 second(s)Memory Limit: 32 MB
A Fi-binary number is a number that contains only 0 and 1. It does not contain any leading 0. And also it does not contain 2 consecutive 1. The first few such number are 1, 10, 100, 101, 1000, 1001, 1010, 10000, 10001, 10010, 10100, 10101 and so on. You are given n. You have to calculate the nth Fi-Binary number.
Input
Input starts with an integer T (≤ 10000), denoting the number of test cases.
Each case contains an integer n (1 ≤ n ≤ 109).
Output
For each case, print the case number and the nth Fi-Binary number
Sample Input
Output for Sample Input
4
10
20
30
40
Case 1: 10010
Case 2: 101010
Case 3: 1010001
Case 4: 10001001
PROBLEM SETTER: ABDULLAH AL MAHMUD
SPECIAL THANKS: JANE ALAM JAN (SOLUTION, DATASET)
#pragma comment(linker, "/STACK:1024000000,1024000000")#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<stack>#include<vector>#include<map>#define L(x) (x<<1)#define R(x) (x<<1|1)#define MID(x,y) ((x+y)>>1)#define bug printf("hihi\n")#define eps 1e-12typedef long long ll;using namespace std;#define mod 1000000007#define N 100ll f[2][N];void inint(){ int i,j; int one,zero; zero=1; one=0; f[0][0]=f[1][0]=0; for(i=1;i<N;i++) { f[0][i]=f[0][i-1]+one+zero; int te=one; one=zero; zero=zero+te; } zero=0; one=1; for(i=1;i<N;i++) { f[1][i]=f[1][i-1]+one+zero; int te=one; one=zero; zero=zero+te; }}void dfs(int st,int n){ if(n==0) return ; if(st==1) { printf("1"); dfs(0,n-1); return ; } printf("0"); n--; if(n==0) return ; int i; for(i=1;i<N;i++) if(f[0][i]+f[1][i]>=n) break; if(n<=f[0][i]+f[1][i-1]) { dfs(0,n-f[1][i-1]); return ; } dfs(1,n-f[0][i]);}int main(){ int i,j,t,ca=0,n; inint(); scanf("%d",&t); while(t--) { scanf("%d",&n); printf("Case %d: ",++ca); dfs(1,n); printf("\n"); } return 0;}
0 0
- Light oj 1105 - Fi Binary Number(计数)
- Light OJ 1105 Fi Binary Number(二分+数位DP)
- lightoj - 1105 - Fi Binary Number - 数位dp
- lightoj 1105 - Fi Binary Number 水
- UVa11089 - Fi-binary Number
- light oj Binary Simulation
- Light oj 1060 - nth Permutation(dfs 计数)
- Light OJ 1095 Arrange the Numbers(计数)
- Light OJ 1382 The Queue(组合计数)
- light oj 1213 - Fantasy of a Summation (数学计数)
- Light OJ 1080 - Binary Simulation
- Light oj 1234 - Harmonic Number
- Light OJ 1234 Harmonic Number
- light oj 1234 Harmonic Number
- [数位dp+二分] LightOJ 1105 - Fi Binary Number
- LightOJ-1105 Fi Binary Number(斐波那契数列)
- UVA 题目11089 Fi-binary Number(找规律)
- Light oj 1245 Harmonic Number (II)(基础数论)
- 最长连续子序列
- eclipse中使用git
- 关于使用模态窗口presentViewController跳转黑屏的解决
- 非递归学习树结构(四)--BST(二叉排序)树
- NAT介绍,防火墙介绍
- Light oj 1105 - Fi Binary Number(计数)
- java集合框架(上)
- LA 4329 - Ping pong(树状数组)
- C++11变参模板的参数包
- Linux Kernel CMPXCHG函数分析
- PMP之4 项目整合管理
- Pascal's Triangle
- 海尔称将开30000微店 家电巨头挖掘朋友圈商机
- 二叉搜索树