UVA11089 Fi-binary Number【数学规律】
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 n-th Fi-Binary number. 问题链接:UVA11089 Fi-binary Number AC的C++语言程序如下: /* UVA11089 Fi-binary Number */ #include <iostream> using namespace std; const int N = 43; int f[N + 1]; void setfib() { f[0] = 1; f[1] = 1; for(int i = 2; i <= N; i++) f[i] = f[i - 2] + f[i - 1]; } void solve(int n) { n--; int k; for (k = 0; f[k] <= n; k++) n -= f[k]; printf("1"); while (k > 1) { if (n < f[k - 1]) { printf("0"); k--; } else { printf("01"); n -= f[k - 1]; k -= 2; } } printf("%sn",k ? "0" : ""); } int main() { setfib(); int t,n; scanf("%d",&t); while(t--) { scanf("%d",&n); solve(n); } return 0; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |