Dotcpp  >  试卷列表  >  NOIP第二十四届全国青少年信息学奥林匹克联赛初赛试题[2018提高组]

NOIP第二十四届全国青少年信息学奥林匹克联赛初赛试题[2018提高组]


第1题

下列四个不同进制的数中,与其它三项数值上不相等的是( )。

共 2 分 

第2题

下列属于解释执行的程序设计语言是( )。

共 2 分 

第3题

中国计算机学会于( )年创办全国青少年计算机程序设计竞赛。

共 2 分 

第4题

设根节点深度为0,一棵深度为h 的满k(k>1)叉树,即除最后一层无任何子节点外,每一层上的所有结点都有k 个子结点的树,共有( )个结点。

共 2 分 

第5题

设某算法的时间复杂度函数的递推方程是T(n) = T(n - 1) + n(n 为正整数)及T(0) = 1,则该算法的时间复杂度为( )。

共 2 分 

第6题

表达式a * d - b * c 的前缀形式是( )。

共 2 分 

第7题

在一条长度为1 的线段上随机取两个点,则以这两个点为端点的线段的期望长度是( )。

共 2 分 

第8题

关于Catalan 数Cn = (2n)! / (n + 1)! / n!,下列说法中错误的是( )。

共 2 分 

第9题

假设一台抽奖机中有红、蓝两色的球,任意时刻按下抽奖按钮,都会等概率获得红球或蓝球之一。有足够多的人每人都用这台抽奖机抽奖,假如他们的策略均为:抽中蓝球则继续抽球,抽中红球则停止。最后每个人都把自己获得的所有球放到一个大箱子里,最终大箱子里的红球与蓝球的比例接近于( )。

共 2 分 

第10题

为了统计一个非负整数的二进制形式中1 的个数,代码如下:

1
2
3
4
5
6
7
8
9
10
int CountBit(int x)
{
     int ret = 0;
     while (x)
     {
       ret++;
       ________;
     }
     return ret;
}

则空格内要填入的语句是( )。

共 2 分 

第11题

NOIP 初赛中,选手可以带入考场的有( )。


共 2 分 

第12题

2-3 树是一种特殊的树,它满足两个条件:
(1)每个内部结点有两个或三个子结点;
(2)所有的叶结点到根的路径长度相同。
如果一棵2-3 树有10 个叶结点,那么它可能有( )个非叶结点。


共 2 分 

第13题

下列关于最短路算法的说法正确的有( )。


共 2 分 

第14题

下列说法中,是树的性质的有( )。


共 2 分 

第15题

下列关于图灵奖的说法中,正确的有( )。


共 2 分 

第16题

甲乙丙丁四人在考虑周末要不要外出郊游。
已知

①如果周末下雨,并且乙不去,则甲一定不去;

②如果乙去,则丁一定去;

③如果丙去,则丁一定不去;

④如果丁不去,而且甲不去,则丙一定不
去。

如果周末丙去了,则甲________(去了/没去),乙________(去了/没去),丁________(去了/没去),周末________(下雨/
没下雨)。


共 5 分 

第17题

方程 a*b = (a or b) *(a and b),在 a,b 都取 [0, 31]中的整数时,共有_____组解。(*∗ 表示乘法;or 表示按位或运算;and 表示按位与运算)

共 5 分 

第18题

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <cstdio>
int main(){
    int x;
    scanf("%d", &x);
    int res = 0;
    for (int i = 0; i < x; ++i){
        if (i * i % x == 1){
            ++res;
        }
    }
    printf("%d", res);
    return 0;
}

输入 :

15

输出 :________


共 8 分 

第19题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <cstdio>
int n, d[100];
bool v[100];
int main(){
    scanf("%d", &n);
    for (int i = 0; i < n; ++i){
        scanf("%d", d + i);
        v[i] = false;
    }
    int cnt = 0;
    for (int i = 0; i < n; ++i){
        if (!v[i]){
            for (int j = i; !v[j]; j = d[j]){
                v[j] = true;
            }
            ++cnt;
        }
    }
    printf("%d
", cnt);
    return 0;
}

输入 :

10 7 1 4 3 2 5 9 8 0 6

输出 :________


共 8 分 

第20题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
using namespace std;
string s;
long long magic(int l, int r){
    long long ans = 0;
    for (int i = l; i <= r; ++i){
        ans = ans * 4 + s[i] - 'a' + 1;
    }
    return ans;
}
int main(){
    cin >> s;
    int len = s.length();
    int ans = 0;
    for (int l1 = 0; l1 < len; ++l1){
        for (int r1 = l1; r1 < len; ++r1){
            bool bo = true;
            for (int l2 = 0; l2 < len; ++l2){
                for (int r2 = l2; r2 < len; ++r2){
                    if (magic(l1, r1) == magic(l2, r2) && (l1 != l2 || r1 != r2)){
                        bo = false;
                    }
                }
            }
            if (bo){
                ans += 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

输入 :

abacaba

输出 :________


共 8 分 

第21题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <cstdio>
using namespace std;
const int N = 110;
bool isUse[N];
int n, t;
int a[N], b[N];
bool isSmall(){
    for (int i = 1; i <= n; ++i)
        if (a[i] != b[i]) return a[i] < b[i];
    return false;
}
bool getPermutation(int pos){
    if (pos > n){
        return isSmall();
    }
    for (int i = 1; i <= n; ++i){
        if (!isUse[i]){
            b[pos] = i; isUse[i] = true;
            if (getPermutation(pos + 1)){
                return true;
            }
            isUse[i] = false;
        }
    }
    return false;
}
void getNext(){
    for (int i = 1; i <= n; ++i){
        isUse[i] = false;
    }
    getPermutation(1);
    for (int i = 1; i <= n; ++i){
        a[i] = b[i];
    }
}
int main(){
    scanf("%d%d", &n, &t);
    for (int i = 1; i <= n; ++i){
        scanf("%d", &a[i]);
    }
    for (int i = 1; i <= t; ++i){
        getNext();
    }
    for (int i = 1; i <= n; ++i){
        printf("%d", a[i]);
        if (i == n) putchar('
'); else putchar(' ');
    }
    return 0;
}

输入1:

6 10 1 6 4 5 3 2

输出1:________

输入2:

6 200 1 5 3 4 2 6

输出2:________


共 8 分 

第22题

对于一个 1 到 n 的排列 P(即 1 到 n 中每一个数在 P 中出现了恰好一次),令 qi 为第 i 个位置之后第一个比 Pi 值更大的位置,如果不存在这样的位置,则 qi=n+1。举例来说,如果 n=5 且 P 为 1 5 4 2 3,则 q 为2 6 6 5 6 。

下列程序读入了排列 P,使用双向链表求解了答案。试补全程序。

数据范围1≤n≤105

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
using namespace std;
const int N = 100010;
int n;
int L[N], R[N], a[N];
int main(){
    cin >> n;
    for (int i = 1; i <= n; ++i){
        int x;
        cin >> x;
        ____(1)____;
    }
    for (int i = 1; i <= n; ++i){
        R[i] = ____(2)____;
        L[i] = i - 1;
    }
    for (int i = 1; i <= n; ++i){
        L[____(3)____] = L[a[i]];
        R[L[a[i]]] = R[____(4)____];
    }
    for (int i = 1; i <= n; ++i){
        cout << ____(5)____ << " ";
    }
    cout << endl;
    return 0;
}


共 14 分 

第23题

一只小猪要买 N 件物品 (N 不超过 1000)。

它要买的所有物品在两家商店里都有卖。第 i 件物品在第一家商店的价格是 a[i],在第二家商店的价格是 b[i],两个价格都不小于 0 且不超过 10000。如果在第一家商店买的物品的总额不少于50000,那么在第一家店买的物品都可以打95 折(价格变为原来的 0.95 倍)。

求小猪买齐所有物品所需最少的总额。

输入:第一行一个数 N。接下来 N 行,每行两个数。第 i 行的两个数分别代表 a[i], b[i]。

输出:输出一行一个数,表示最少需要的总额,保留两位小数。

试补全程序。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <cstdio>
#include <algorithm>
using namespace std;
 
const int Inf = 1000000000;
const int threshold = 50000;
const int maxn = 1000;
 
int n, a[maxn], b[maxn];
bool put_a[maxn];
int total_a, total_b;
double ans;
int f[threshold];
 
int main() {
    scanf("%d", &n);
    total_a = total_b = 0;
    for (int i = 0; i < n; ++i) {
        scanf("%d%d", a + i, b + i);
        if (a[i] <= b[i]) total_a += a[i];
        else total_b += b[i];
    }
    ans = total_a + total_b;
    total_a = total_b = 0;
    for (int i = 0; i < n; ++i) {
        if (____(1)____) {
            put_a[i] = true;
            total_a += a[i];
        }
        else{
            put_a[i] = false;
            total_b += b[i];
        }
    }
    if (____(2)____) {
        printf("%.2f", total_a * 0.95 + total_b);
        return 0;
    }
    f[0] = 0;
    for (int i = 1; i < threshold; ++i)
        f[i] = Inf;
    int total_b_prefix = 0;
    for (int i = 0; i < n; ++i) {
        if (!put_a[i]) {
            total_b_prefix += b[i];
            for (int j = threshold - 1; j >= 0; --j) {
                if (____(3)____ >= threshold && f[j] != Inf)
                    ans = min(ans, (total_a + j + a[i]) * 0.95 + ____(4)____);
                f[j] = min(f[j] + b[i], j >= a[i] ? ____(5)____ : Inf);
            }
        }
    }
    printf("%.2f", ans);
    return 0;
}


共 14 分 

试卷信息

题量: 23 道
总分: 100 分
一、单项选择题(1-10 共 10 题);
二、不定项选择题(11-15 共 15 题);
三、问题求解(16-17 共 2 题);
四、阅读程序写结果。(18-21 共 4 题);
五、完善程序(22-23 共 2 题)。