zoukankan      html  css  js  c++  java
  • 2014第五届蓝桥杯试题C/C++程序设计B组——切面条

    题目描述:
    标题:切面条

    一根高筋拉面,中间切一刀,可以得到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

  • 相关阅读:
    module模块和包(十七)
    swap(十六)
    文件系统
    Confluence 6 管理协同编辑
    Confluence 6 管理协同编辑
    Confluence 6 数据收集隐私策略
    Confluence 6 修改警告的阈值和表现
    Confluence 6 警告的类型
    Confluence 6 诊断
    Confluence 6 垃圾收集性能问题
  • 原文地址:https://www.cnblogs.com/123qw/p/4414157.html
Copyright © 2011-2022 走看看