zoukankan      html  css  js  c++  java
  • Computer Transformation

    题意 从1开始 1变为01 0变为10 计数变换多少次后连续0序列的个数。

    题解 找规律(菲波数)+大数相加

    a[i]=a[i-1]+a[i-2]*2;

     1 #include <stdio.h>
     2 #include<iostream>
     3 #include<cstring>
     4 #define N 1001
     5 using namespace std;
     6 char a[N][N];
     7 
     8 int main()
     9 {
    10     memset(a,'0',sizeof(a)); 
    11     a[2][0]='1';
    12     a[3][0]='1';
    13     int i,j,d=1;
    14     for(i=4;i<N;i++)//i控制行数 
    15     {
    16         d++;   //控制列数 
    17         int c=0,s;  //c为进位指数的初值 
    18         for(j=0;j<=d;j++)      //j控制列数的循环
    19         {
    20             s=a[i-1][j]-'0'+a[i-2][j]-'0'+a[i-2][j]-'0'+c;
    21             c=s/10; //满十进位
    22             a[i][j]=s%10+'0';   //满十的话,将舍位
    23         }
    24     }
    25 
    26     int t,n;
    27 
    28     char s[1000];
    29 
    30         while(~scanf("%d",&n))
    31         {
    32 
    33         if(n==1)
    34             puts("0");
    35         else
    36         {
    37         int k=N-1;
    38 
    39         while(k--)
    40 
    41         {
    42 
    43             if(a[n][k]!='0') break;    //反向搜索第一个不为‘0’的字符
    44 
    45         }
    46 
    47         for(i=k;i>=0;i--)  //从后往前输出
    48 
    49             printf("%c",a[n][i]);
    50 
    51        printf("
    ");
    52         }
    53 
    54     }
    55 
    56     return 0;
    57 
    58 }
  • 相关阅读:
    感悟贴2016-05-13
    操作系统原理部分
    java-NIO
    centos7下环境配置
    mysql 链接驱动问题
    ComboPooledDataSource 连接池耗完
    mvn使用问题
    js button onclick动作赋值操作
    git操作之git clean删除一些没有git add的文件
    VMware虚拟机网络设置
  • 原文地址:https://www.cnblogs.com/awsent/p/4267304.html
Copyright © 2011-2022 走看看