万卷网 > 题目详情
题型:组合题
include <algorithm>
include <cstdio>
include <cstring>
define ll long long
int cnt_broken = 0;
int cnt_check = 0;
int n, k;
inline bool check(int h) {
    printf("now check:%d\n", h);
    ++cnt_check;
    if (cnt_broken == 2) {
        printf("You have no egg!\n");
        return false;
    }
    if (h >= k) {
        ++cnt_broken;
        return true;
    } else {
        return false;
    }
}
inline bool assert_ans(int h) {
    if (h == k) {
        printf("You are Right using %d checks\n", cnt_check);
        return true;
    } else {
        printf("Wrong answer!\n");
        return false;
    }
}
inline void guess1(int n) {
    for (int i = 1; i <= n; ++i) {
        if (check(i)) {
            assert_ans(i);
            return;
        }
    }
}
inline void guess2(int n) {
    int w = 1;
    while (w * (w + 1) / 2 < n) {
        ++w;
    }
    int ti = w;
    int nh = 0;
    while (true) {
        nh += ti;
        if (nh > n) {
            nh = n;
        }
        if (check(nh)) {
            for (int j = nh ti + 1; j < nh; ++j) {
                if (check(j)) {
                    assert_ans(j);
                    return;
                }
            }
            assert_ans(nh);
            return;
        }
        --ti;
        if (ti == 0) {
            assert_ans(n);
            return;
        }
    }
}
int main() {
    scanf("%d%d", &n, &k);
    int t;
    scanf("%d", &t);
    if (t == 1) {
        guess1(n);
    } else {
        guess2(n);
    }
    return 0;
}
(1).

函数guess2在运行过程中,最多使用的猜测次数的量级为? 

A.

O(n)

B.

O(n²)

C.

O(√n)

D.

O(logn)

(2).

不管输入的n和k具体为多少,t=2时的猜测数总是小于等于t=1时的猜测数。

A.正确 B.错误
(3).

函数guess1在运行过程中,cnt_broken的值最多为?

A.

0

B.

1

C.

2

D.

n

(4).

不管t=1或t=2,程序都一定会猜到正确结果。

A.正确 B.错误
(5).

当输入为“6 5 1”时,猜测次数为5;当输入“6 5 2”时,猜测次数为3。

A.正确 B.错误
(6).

当输入的n=100的时候,代码中t=1和t=2分别需要的猜测次数最多分别为?

A.

100,14

B.

100,13

C.

99,14

D.

99,13

更新时间:2025-10-17 20:09:19 |
【知识点】 CCF非专业级别软件能力认证CSP-S/提高级

相似题推荐

简答题

T4员工招聘

2026-04-17
简答题

T1社团招新

2026-04-17
简答题

T2道路修复

2026-04-17
简答题

T3谐音替换

2026-04-16
单选题

对一个大小为16(下标0-15)的数组构建满线段树,查询区间[3,11]时,最少需要访问多少个树结点(包括路径上的父结点和完全包含在查询区间内的结点)?

A.

7

B.

8

C.

9

D.

10

2025-10-17
公众号
客服 反馈
顶部