#CS40110. 阅读程序-1模拟策略-10

阅读程序-1模拟策略-10

阅读程序

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

第一节:模拟策略

第10题【NOIP】2014

#include<iostream>
using namespace std;
const int    SIZE = 100;
int        alive[SIZE];
int        n;
int next( int num ){
    do {
        num++;
        if ( num > n )num = 1;
    }while ( alive[num] == 0 );
    return num;
}
int main(){
    int m, i, j, num;
    cin>>n>>m;
    for ( i = 1; i <= n; i++ )
        alive[i] = 1;
    num = 1;
    for ( i = 1; i <= n; i++ ){
        for ( j = 1; j < m; j++ )
            num = next( num );
        cout<<num<<" ";
        alive[num] = 0;
        if ( i < n )num = next( num );
    }
    cout<<endl;
    return 0;
}

●判断题

(1)若输入100 0,该程序会运行错误。

{{ select(10-1) }}

(2)若把17行去掉,程序结果不会发生改变。

{{ select(10-2) }}

(3)如果把24行的“<”改为“<=”,则程序结果发生改变。

{{ select(10-3) }}

(4)若输入11 3,则输出3 6 9 1 5 10 4 11 8 2 7

{{ select(10-4) }}

●选择题

(5)该程序的最坏时间复杂度为( )。

{{ select(10-5) }}

  • O(1)
  • O(n)
  • O(n*m)
  • O(2n2^n)

(6)若输入为10 4,则第4个数为( )。

{{ select(10-6) }}

  • 5
  • 6
  • 7
  • 8