题型:组合题
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) |
不管输入的n和k具体为多少,t=2时的猜测数总是小于等于t=1时的猜测数。
| A.正确 | B.错误 |
函数guess1在运行过程中,cnt_broken的值最多为?
| A. 0 |
B. 1 |
| C. 2 |
D. n |
不管t=1或t=2,程序都一定会猜到正确结果。
| A.正确 | B.错误 |
当输入为“6 5 1”时,猜测次数为5;当输入“6 5 2”时,猜测次数为3。
| A.正确 | B.错误 |
当输入的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/提高级
抱歉! 您未登录, 不能查看答案和解析点击登录












