#CS41009. 阅读程序10-数论9

阅读程序10-数论9

阅读程序

注意:切勿用电脑直接运行代码得出答案,请用大脑+笔+纸运行代码答题,否则是在浪费你的时间。

第10节:数论

第9题【NOIP】2012

#include <iostream>
using namespace std;
const int SIZE = 20;
int data[SIZE];
int n, i, h, ans;
void merge()
{
    data[h-1] = data[h-1] + data[h];
    h--;
    ans++;
}
int main()
{
    cin>>n;
    h = 1;
    data[h] = 1;
17  ans = 0;
    for (i = 2; i <= n; i++)
    {
        h++;
        data[h] = 1;
22      while (h > 1 && data[h] == data[h-1])
            merge();
    }
    cout<<ans<<endl;
}

●判断题

(1)去掉第17行,程序输出结果不变

{{ select(9-1) }}

  • 正确
  • 错误

(2)输入5,输出结果为3。

{{ select(9-2) }}

  • 正确
  • 错误

(3)将第22行的“==“改为“>=”,程序输出结果会改变。

{{ select(9-3) }}

  • 正确
  • 错误

(4)输入2147483647,程序一定正常运行。

{{ select(9-4) }}

  • 正确
  • 错误

●选择题

(5)输人2012,输出结果为

{{ select(9-5) }}

  • 2004
  • 2015
  • 2018
  • 2006

(6)ans的上界为

{{ select(9-6) }}

  • n
  • n\sqrt{n}
  • logn
  • nn\sqrt{n}