Children’s Queue

 1 import java.util.*;
 2  import java.math.*;
 3  public class Main
 4  {
 5      public static void main(String []args)
 6      {
 7          Scanner cin=new Scanner(System.in);
 8          int i,n;
 9          while(cin.hasNext())
10          {    
11              n=cin.nextInt();
12              BigInteger s1 = BigInteger.valueOf(1);
13              BigInteger s2 = BigInteger.valueOf(2);
14              BigInteger s3 = BigInteger.valueOf(4);
15              BigInteger s4 = BigInteger.valueOf(7);
16              BigInteger s5 = BigInteger.valueOf(12);
17              if(n==1)
18               System.out.println(s1);
19               else if(n==2)
20                System.out.println(s2);
21                else if(n==3)
22                 System.out.println(s3);
23                 else if(n==4)
24                  System.out.println(s4);
25                  else
26                  {
27              for(i=5;i<=n;i++)
28              {
29                  s5 = s4.add(s3.add(s1));
30                  s1=s2;
31                  s2=s3;
32                  s3=s4;
33                  s4=s5;
34              }
35              System.out.println(s5);  
36              }  
37          }
38      }
39  }

这个题的规律真难找,我承认,我自己找的时候真没找出来,主要是自己有些结果错了,导致规律没找出来,自己真不细心呢!还是说一句,这个规律坑死我了!!

posted @ 2012-06-23 23:42  欧阳生朵  阅读(330)  评论(0编辑  收藏  举报