专栏首页mlHDUOJ-----Computer Transformation

HDUOJ-----Computer Transformation

Computer Transformation

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4842    Accepted Submission(s): 1769

Problem Description

A sequence consisting of one digit, the number 1 is initially written into a computer. At each successive time step, the computer simultaneously tranforms each digit 0 into the sequence 1 0 and each digit 1 into the sequence 0 1. So, after the first time step, the sequence 0 1 is obtained; after the second, the sequence 1 0 0 1, after the third, the sequence 0 1 1 0 1 0 0 1 and so on. How many pairs of consequitive zeroes will appear in the sequence after n steps?

Input

Every input line contains one natural number n (0 < n ≤1000).

Output

For each input n print the number of consecutive zeroes pairs that will appear in the sequence after n steps.

Sample Input

2

3

Sample Output

1

1

做这道题,纯粹是一道大数的题,当然你需要推导出这个公式f[n]=f[n-1]+2*f[n-2];

 1 #include<cstdio>
 2 const int maxn=1000;
 3 int arr[maxn+1][305]={0};
 4 int len=1;
 5 void LargeNum()
 6 {
 7      arr[1][0]=1;
 8     for(int i=2;i<=maxn;i++)
 9     {
10         int c=0;
11         for(int j=0;j<len;j++)
12         {
13           arr[i][j]+=arr[i-1][j]+2*arr[i-2][j]+c;
14           if(arr[i][len-1]>9)
15               len++;
16            c=arr[i][j]/10;
17              arr[i][j]%=10;
18         }
19     }
20 
21 }
22 int main( void )
23 { 
24     int n,i;
25     LargeNum();
26     while(scanf("%d",&n)==1)
27     {
28         if(n==1)puts("0");
29         else
30         {
31         for(i=len;arr[n-1][i]==0;i--);
32         for(int j=i;j>=0;j--)
33               printf("%d",arr[n-1][j]);
34         puts("");
35         }
36     }
37     return 0;
38 }

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • HDUOJ----Eddy's research I

    Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/...

    Gxjun
  • HDUOJ---3371Connect the Cities

    Connect the Cities Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768...

    Gxjun
  • HDUOJ----1301 Jungle Roads

    Jungle Roads Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768...

    Gxjun
  • HDUOJ----Eddy's research I

    Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/...

    Gxjun
  • 11-散列2 Hashing (25分)

    The task of this problem is simple: insert a sequence of distinct positive integ...

    AI那点小事
  • pta 习题集 5-5 最长连续递增子序列 (dp)

    Count the Sheep Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/6...

    ShenduCC
  • HDU 6016 Count the Sheep

    Count the Sheep Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/6...

    ShenduCC
  • HDUOJ-----(1162)Eddy's picture(最小生成树)

    Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327...

    Gxjun
  • 【PAT甲级】The Black Hole of Numbers

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 ...

    喜欢ctrl的cxk
  • ubuntu16.0.4 opencv4.0.0 yolov3测试

    硬件信息 8 Intel® Core™ i7-4790 CPU @ 3.60GHz

    用户1148525

扫码关注云+社区

领取腾讯云代金券