zoukankan      html  css  js  c++  java
  • 数列

    给定a,b和递推式

    x[1]=1

    x[n]=a*x[n-1]+b

    小y想知道,当n无穷大时,x[n]是否无穷大?

    输入:

    给定A,B,题意中a=A/1e9,b=B/1e9

    输出:

    一行一个yes或no

    样例输入:

    0 1

    2000000000 1

    输出:

    no

    yes

    a=1时,判断b是否为0就行

    x[n]=a*x[n-1]+b

    x[n]+b/(a-1)=a*(x[n-1]+b/(a-1))

    x[n]+b/(a-1)=a^n*(1+b/(a-1))

    x[n]=(a^n(a+b-1)-b)/(a-1)

    现在就很好做了,分类讨论

    注意不要把把A,B除了,会有精度问题,直接把1e9作基准

    其实还有简单的方法,算出来:

    x[n]=a^n+b*a^(n-1)+b*a^(n-2).......+b

    x[n]=a^n+b*(a^n-1)/(a-1)

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<cstring>
     5 using namespace std;
     6 double a,b;
     7 int main()
     8 {
     9  while (cin>>a>>b)
    10  {
    11   a=a;
    12   b=b;
    13   //printf("%.9lf %.9lf
    ",a,b);
    14   if (a>=0&&a<1e9)
    15     {
    16       printf("no
    ");
    17     }
    18   if (a==1e9)
    19     {
    20       if (b!=0)
    21       printf("yes
    ");
    22       else printf("no
    ");
    23     }
    24   if (a>1)
    25     {
    26       if (b!=1e9-a)
    27       printf("yes
    ");
    28       else printf("no
    ");
    29     }
    30   if (a==-1e9)
    31     {
    32       printf("no
    ");
    33     }
    34   if (a<0&&a>-1e9)
    35     {
    36       printf("no
    ");
    37     }
    38   if (a<-1e9)
    39     {
    40       if (b!=1e9-a)
    41     printf("yes
    ");
    42       else printf("no
    ");
    43     }
    44  }
    45 }
  • 相关阅读:
    mysql 权限问题
    触发器作用
    带有循环功能的存储过程
    带有条件判断的存储过程
    数据存储 三大范式-----------待续
    存储过程自 带条件判断的存储过程
    线程异步更新UI
    TextBox只能输入数字
    C#中无边框窗体移动或拖控件移动窗体
    classloader原理
  • 原文地址:https://www.cnblogs.com/Y-E-T-I/p/7609372.html
Copyright © 2011-2022 走看看