zoukankan      html  css  js  c++  java
  • hdu1021(Fibonacci)

    这道题要找规律,找完规律后发现简单到要死。抓狂

    下标 0  1  2  3  4  5  6  7  8  9  10  11  12  13
    值  1  2  0  2  2  1  0  1  1  2   0    2     2   1
    输出  no   no  yes  no no    no  yes  no  no  no    yes   no  no  no
    这样我们就得到了如下规律:从第2个开始每隔4个循环一次。


    法一:找规律,T=4

    #include <stdio.h>
    int main()
    {
    int i,n;
    while (~scanf("%d",&n))
    {
    
    if((n-2)%4==0)
    printf("yes
    ");
    else 
    printf("no
    ");
    }
    
    return 0;
    }
    法二:T=8
    #include<stdio.h>
    int main()
    {
    int f[10],n,i;
    while(scanf("%d",&n)!=EOF)
       {
        n=n%8;
        f[0]=7;f[1]=11;
        for(i=2;i<=n;i++)
          f[i]=f[i-1]+f[i-2];
        if(f[n]%3==0)
          printf("yes
    ");
        else
          printf("no
    ");
       }
    return 0;
    }


    法三:(似懂非懂)

    #include <stdio.h>
    int a[1000009];
    int i;
    int main ()
    {
        int n;
        a[0] = 7 % 3;
        a[1] = 11 % 3;  
        for ( i = 2; i < 1000009; i ++ )
        {
            a[i] = ( a[i - 1] + a[i - 2] ) % 3;
        }
        
        while ( scanf ("%d", &n) != EOF )
        {
              if ( !a[n] )
                 printf ("yes
    ");
              else
               printf ("no
    ");
        }
        
        return 0;
    }



  • 相关阅读:
    QT多个UI文件加入一个项目
    【Go语言】学习资料
    MVC如何在Pipeline中接管请求的?
    ASP.NET MVC路由(5)
    C# dll 事件执行 js 回调函数
    初识Identity
    SpringMVC拦截器
    UrlRouting的理解
    ASP.NET MVC路由
    ASP.NET MVC Module
  • 原文地址:https://www.cnblogs.com/qie-wei/p/12094150.html
Copyright © 2011-2022 走看看