zoukankan      html  css  js  c++  java
  • Java编程:切面条

    /* 一根高筋拉面,中间切一刀,能够得到2根面条。
        假设先对折1次。中间切一刀。能够得到3根面条。
        假设连续对折2次,中间切一刀。能够得到5根面条。
        那么。连续对折10次。中间切一刀。会得到多少面条呢?
        -------------------------------------------
    对折0次,得到2根;
    对折1次,得到2 * 2 - 1 = 3
    对折2次,得到3 * 2 - 1 = 5  
    对折3次。得到5 * 2 - 1 = 9
    对折4次,得到9 * 2 - 1 = 17
    对折5次,得到17 * 2 - 1 = 33
    对折6次,得到33 * 2 - 1 = 65
    对折7次,得到65 * 2 - 1 = 129
    对折8次,得到129 * 2 - 1 = 257
    对折9次,得到257 * 2 - 1 = 513
    对折10次,得到513 * 2 - 1 = 1025*/
    public class Test2 {
    	public static int F(int n)
    	{
    		if(n==0)
    			return 2;
    		return 2*F(n-1)-1;
    	}
    	public static void main(String[] args) {
    
    		System.out.println("对折10次得到"+Test2.F(10)+"根苗条");
    		
    	}
    
    }
    

  • 相关阅读:
    qsort
    strcmp
    LotteryDrawing
    retire or not retire ? is a question.
    alloc && afree
    strlen
    c point
    c point ccccc
    MySQL MGR源码分析2
    MySQL MGR实现分析
  • 原文地址:https://www.cnblogs.com/jzssuanfa/p/7132321.html
Copyright © 2011-2022 走看看