2014第五届蓝桥杯试题——切面条

时间:2015-04-10 12:59:19   收藏:0   阅读:2953

题目描述:
标题:切面条

一根高筋拉面,中间切一刀,可以得到2根面条。

如果先对折1次,中间切一刀,可以得到3根面条。

如果连续对折2次,中间切一刀,可以得到5根面条。

那么,连续对折10次,中间切一刀,会得到多少面条呢?

答案是个整数,请通过浏览器提交答案。不要填写任何多余的内容。

 


ps:

对折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

可使用递归函数解决


代码:

#include <stdio.h>
#include <stdlib.h>

 

int count(int n){
  if(n==0){
    return 2;
  }else{
    return 2*count(n-1)-1;
  }
}

int main(int argc, char *argv[]) {
  int value = count(10);
  printf("%d",value);
  return 0;
}

 


答案:1025

 

原文:http://www.cnblogs.com/123qw/p/4414157.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!