返回试卷目录

需要电子版时点「打印 / 保存为 PDF」,在打印对话框的「目标打印机」里选择「另存为 PDF」即可下载。登录后可下载,每天 10 次

CSP-J 第一轮 · 2021 年真题

CSP-J/S · C++ · 共 43 题 · 满分 100 分

姓名:____________日期:____________得分:____________

  1. 1.单选题2 分
    1. 以下不属于面向对象程序设计语言的是( )。
    • A.C++
    • B.Python
    • C.Java
    • D.C
  2. 2.单选题2 分
    2. 以下奖项与计算机领域最相关的是( )。
    • A.奥斯卡奖
    • B.图灵奖
    • C.诺贝尔奖
    • D.普利策奖
  3. 3.单选题2 分
    3. 目前主流的计算机储存数据最终都是转换成( )数据进行储存。
    • A.二进制
    • B.十进制
    • C.八进制
    • D.十六进制
  4. 4.单选题2 分
    4. 以比较作为基本运算,在N个数中找出最大数,最坏情况下所需要的最少的比较次数为( )。
    • A.N^2
    • B.N
    • C.N-1
    • D.N+1
  5. 5.单选题2 分
    5. 对于入栈顺序为a,b,c,d,e的序列,下列( )不是合法的出栈序列。
    • A.a,b,c,d,e
    • B.e,d,c,b,a
    • C.b,a,c,d,e
    • D.c,d,a,e,b
  6. 6.单选题2 分
    6. 对于有n个顶点、m条边的无向连通图(m>n),需要删掉( )条边才能使其成为一棵树。
    • A.n-1
    • B.m-n
    • C.m-n-1
    • D.m-n+1
  7. 7.单选题2 分
    7. 二进制数101.11对应的十进制数是( )。
    • A.6.5
    • B.5.5
    • C.5.75
    • D.5.25
  8. 8.单选题2 分
    8. 如果一棵二叉树只有根结点,那么这棵二叉树高度为1。请问高度为5的完全二叉树有( )种不同形态?
    • A.16
    • B.15
    • C.17
    • D.32
  9. 9.单选题2 分
    9. 表达式a*(b+c)*d的后缀表达式为( ),其中"*"和"+"是运算符。
    • A.**a+bcd
    • B.abc+*d*
    • C.abc+d**
    • D.*a*+bcd
  10. 10.单选题2 分
    10. 6个人,两个人组一队,总共组成三队,不区分队伍的编号,不同的组队情况有( )种。
    • A.10
    • B.15
    • C.30
    • D.20
  11. 11.单选题2 分
    11. 在数据压缩编码中的哈夫曼编码方法,在本质是一种( )的策略。
    • A.枚举
    • B.贪心
    • C.递归
    • D.动态规划
  12. 12.单选题2 分
    12. 由1, 1, 2, 2, 3这五个数字组成不同的三位数有( )种。
    • A.18
    • B.15
    • C.12
    • D.24
  13. 13.单选题2 分
    13. 考虑如下递归算法,则调用solve( 7 )得到的返回结果为( )
    solve(n)    if n <= 1 return 1    else if n >= 5 return n*solve(n-2)    else return n*solve(n-1)
    • A.105
    • B.840
    • C.210
    • D.420
  14. 14.单选题2 分
    14. 以a为起点,对右图的无向图进行深度优先遍历,则b、c、d、e四个点中有可能作为最后一个遍历到的点个数为( )。
    • A.1
    • B.2
    • C.3
    • D.4 右图:5 个顶点 a、b、c、d、e;边为 a-b、a-c、b-d、c-d、c-e(a 在上方,b 在左,c 在右,d 在下方,e 由 c 向右下引出)。
  15. 15.单选题2 分
    15. 有四个人要从A点坐一条船过河到B点,船一开始在A点。该船一次最多可坐两个人。已知这四个人中每个人独自坐船的过河时间分别为1, 2, 4, 8, 且两个人坐船的过河时间为两人独自过河时间的较大者。则最短( )时间可以让四个人都过河到B点(包括从B点把船开回A点时间)。
    • A.14
    • B.15
    • C.16
    • D.17
  16. 16.判断题1.5 分
    阅读以下程序: 判断题正确填 √,错误填 ×。
    #include <iostream>using namespace std;int n;int a[1000];int f(int x){    int ret = 0;    for (; x; x &= x-1) ret++;    return ret;}int g(int x){    return x & -x;}int main(){    cin >> n;    for (int i = 0; i < n; i++) cin >> a[i];    for (int i = 0; i < n; i++)        cout << f(a[i]) + g(a[i]) << ' ';    cout << endl;    return 0;}
    16. 输入的n等于1001时,程序不会发生下标越界( )。
  17. 17.判断题1.5 分
    阅读以下程序: 判断题正确填 √,错误填 ×。
    #include <iostream>using namespace std;int n;int a[1000];int f(int x){    int ret = 0;    for (; x; x &= x-1) ret++;    return ret;}int g(int x){    return x & -x;}int main(){    cin >> n;    for (int i = 0; i < n; i++) cin >> a[i];    for (int i = 0; i < n; i++)        cout << f(a[i]) + g(a[i]) << ' ';    cout << endl;    return 0;}
    17. 输入的a[i]必须全为正整数,否则程序将陷入死循环。( )
  18. 18.判断题1.5 分
    阅读以下程序: 判断题正确填 √,错误填 ×。
    #include <iostream>using namespace std;int n;int a[1000];int f(int x){    int ret = 0;    for (; x; x &= x-1) ret++;    return ret;}int g(int x){    return x & -x;}int main(){    cin >> n;    for (int i = 0; i < n; i++) cin >> a[i];    for (int i = 0; i < n; i++)        cout << f(a[i]) + g(a[i]) << ' ';    cout << endl;    return 0;}
    18. 当输入"5 2 11 9 16 10"时,输出为"3 4 3 17 5" 。( )
  19. 19.判断题1.5 分
    阅读以下程序: 判断题正确填 √,错误填 ×。
    #include <iostream>using namespace std;int n;int a[1000];int f(int x){    int ret = 0;    for (; x; x &= x-1) ret++;    return ret;}int g(int x){    return x & -x;}int main(){    cin >> n;    for (int i = 0; i < n; i++) cin >> a[i];    for (int i = 0; i < n; i++)        cout << f(a[i]) + g(a[i]) << ' ';    cout << endl;    return 0;}
    19. 当输入为"1 511998"时,输出为"18" 。( )
  20. 20.判断题1.5 分
    阅读以下程序: 判断题正确填 √,错误填 ×。
    #include <iostream>using namespace std;int n;int a[1000];int f(int x){    int ret = 0;    for (; x; x &= x-1) ret++;    return ret;}int g(int x){    return x & -x;}int main(){    cin >> n;    for (int i = 0; i < n; i++) cin >> a[i];    for (int i = 0; i < n; i++)        cout << f(a[i]) + g(a[i]) << ' ';    cout << endl;    return 0;}
    20. 将源代码中g函数的定义(14-17行)移到main函数的后面,程序可以正常编译运行。( )
  21. 21.单选题3 分
    阅读以下程序: 判断题正确填 √,错误填 ×。
    #include <iostream>using namespace std;int n;int a[1000];int f(int x){    int ret = 0;    for (; x; x &= x-1) ret++;    return ret;}int g(int x){    return x & -x;}int main(){    cin >> n;    for (int i = 0; i < n; i++) cin >> a[i];    for (int i = 0; i < n; i++)        cout << f(a[i]) + g(a[i]) << ' ';    cout << endl;    return 0;}
    21. 当输入为"2 -65536 2147483647"时,输出为( )。
    • A.65532 33
    • B.65552 32
    • C.65535 34
    • D.65554 33
  22. 22.判断题1.5 分
    阅读以下程序: 判断题正确填 √,错误填 ×。
    #include <iostream>#include <string>using namespace std;char base[64];char table[256];void init(){    for (int i = 0; i < 26; i++) base[i] = 'A' + i;    for (int i = 0; i < 26; i++) base[26 + i] = 'a' + i;    for (int i = 0; i < 10; i++) base[52 + i] = '0' + i;    base[62] = '+', base[63] = '/';    for (int i = 0; i < 256; i++) table[i] = 0xff;    for (int i = 0; i < 64; i++) table[base[i]] = i;    table['='] = 0;}string decode(string str){    string ret;    int i;    for (i = 0; i < str.size(); i += 4) {        ret += table[str[i]] << 2 | table[str[i + 1]] >> 4;        if (str[i + 2] != '=')            ret += (table[str[i + 1]] & 0x0f) << 4 | table[str[i + 2]] >> 2;        if (str[i + 3] != '=')            ret += table[str[i + 2]] << 6 | table[str[i + 3]];    }    return ret;}int main(){    init();    cout << int(table[0]) << endl;    string str;    cin >> str;    cout << decode(str) << endl;    return 0;}
    22. 输出的第二行一定是由小写字母、大写字母、数字和"+"、"/"、"="构成的字符串。( )
  23. 23.判断题1.5 分
    阅读以下程序: 判断题正确填 √,错误填 ×。
    #include <iostream>#include <string>using namespace std;char base[64];char table[256];void init(){    for (int i = 0; i < 26; i++) base[i] = 'A' + i;    for (int i = 0; i < 26; i++) base[26 + i] = 'a' + i;    for (int i = 0; i < 10; i++) base[52 + i] = '0' + i;    base[62] = '+', base[63] = '/';    for (int i = 0; i < 256; i++) table[i] = 0xff;    for (int i = 0; i < 64; i++) table[base[i]] = i;    table['='] = 0;}string decode(string str){    string ret;    int i;    for (i = 0; i < str.size(); i += 4) {        ret += table[str[i]] << 2 | table[str[i + 1]] >> 4;        if (str[i + 2] != '=')            ret += (table[str[i + 1]] & 0x0f) << 4 | table[str[i + 2]] >> 2;        if (str[i + 3] != '=')            ret += table[str[i + 2]] << 6 | table[str[i + 3]];    }    return ret;}int main(){    init();    cout << int(table[0]) << endl;    string str;    cin >> str;    cout << decode(str) << endl;    return 0;}
    23. 可能存在输入不同,但输出的第二行相同的情形。( )
  24. 24.判断题1.5 分
    阅读以下程序: 判断题正确填 √,错误填 ×。
    #include <iostream>#include <string>using namespace std;char base[64];char table[256];void init(){    for (int i = 0; i < 26; i++) base[i] = 'A' + i;    for (int i = 0; i < 26; i++) base[26 + i] = 'a' + i;    for (int i = 0; i < 10; i++) base[52 + i] = '0' + i;    base[62] = '+', base[63] = '/';    for (int i = 0; i < 256; i++) table[i] = 0xff;    for (int i = 0; i < 64; i++) table[base[i]] = i;    table['='] = 0;}string decode(string str){    string ret;    int i;    for (i = 0; i < str.size(); i += 4) {        ret += table[str[i]] << 2 | table[str[i + 1]] >> 4;        if (str[i + 2] != '=')            ret += (table[str[i + 1]] & 0x0f) << 4 | table[str[i + 2]] >> 2;        if (str[i + 3] != '=')            ret += table[str[i + 2]] << 6 | table[str[i + 3]];    }    return ret;}int main(){    init();    cout << int(table[0]) << endl;    string str;    cin >> str;    cout << decode(str) << endl;    return 0;}
    24. 输出的第一行为"-1"。( )
  25. 25.单选题3 分
    阅读以下程序: 判断题正确填 √,错误填 ×。
    #include <iostream>#include <string>using namespace std;char base[64];char table[256];void init(){    for (int i = 0; i < 26; i++) base[i] = 'A' + i;    for (int i = 0; i < 26; i++) base[26 + i] = 'a' + i;    for (int i = 0; i < 10; i++) base[52 + i] = '0' + i;    base[62] = '+', base[63] = '/';    for (int i = 0; i < 256; i++) table[i] = 0xff;    for (int i = 0; i < 64; i++) table[base[i]] = i;    table['='] = 0;}string decode(string str){    string ret;    int i;    for (i = 0; i < str.size(); i += 4) {        ret += table[str[i]] << 2 | table[str[i + 1]] >> 4;        if (str[i + 2] != '=')            ret += (table[str[i + 1]] & 0x0f) << 4 | table[str[i + 2]] >> 2;        if (str[i + 3] != '=')            ret += table[str[i + 2]] << 6 | table[str[i + 3]];    }    return ret;}int main(){    init();    cout << int(table[0]) << endl;    string str;    cin >> str;    cout << decode(str) << endl;    return 0;}
    25. 设输入字符串长度为n,decode函数的时间复杂度为( )。
    • A.θ(√n)
    • B.θ(n)
    • C.θ(nlogn)
    • D.θ(n^2)
  26. 26.单选题3 分
    阅读以下程序: 判断题正确填 √,错误填 ×。
    #include <iostream>#include <string>using namespace std;char base[64];char table[256];void init(){    for (int i = 0; i < 26; i++) base[i] = 'A' + i;    for (int i = 0; i < 26; i++) base[26 + i] = 'a' + i;    for (int i = 0; i < 10; i++) base[52 + i] = '0' + i;    base[62] = '+', base[63] = '/';    for (int i = 0; i < 256; i++) table[i] = 0xff;    for (int i = 0; i < 64; i++) table[base[i]] = i;    table['='] = 0;}string decode(string str){    string ret;    int i;    for (i = 0; i < str.size(); i += 4) {        ret += table[str[i]] << 2 | table[str[i + 1]] >> 4;        if (str[i + 2] != '=')            ret += (table[str[i + 1]] & 0x0f) << 4 | table[str[i + 2]] >> 2;        if (str[i + 3] != '=')            ret += table[str[i + 2]] << 6 | table[str[i + 3]];    }    return ret;}int main(){    init();    cout << int(table[0]) << endl;    string str;    cin >> str;    cout << decode(str) << endl;    return 0;}
    26. 当输入为Y3Nx 时,输出的第二⾏为( )。
    • A."csp"
    • B."csq"
    • C."CSP"
    • D."Csp"
  27. 27.单选题3.5 分
    阅读以下程序: 判断题正确填 √,错误填 ×。
    #include <iostream>#include <string>using namespace std;char base[64];char table[256];void init(){    for (int i = 0; i < 26; i++) base[i] = 'A' + i;    for (int i = 0; i < 26; i++) base[26 + i] = 'a' + i;    for (int i = 0; i < 10; i++) base[52 + i] = '0' + i;    base[62] = '+', base[63] = '/';    for (int i = 0; i < 256; i++) table[i] = 0xff;    for (int i = 0; i < 64; i++) table[base[i]] = i;    table['='] = 0;}string decode(string str){    string ret;    int i;    for (i = 0; i < str.size(); i += 4) {        ret += table[str[i]] << 2 | table[str[i + 1]] >> 4;        if (str[i + 2] != '=')            ret += (table[str[i + 1]] & 0x0f) << 4 | table[str[i + 2]] >> 2;        if (str[i + 3] != '=')            ret += table[str[i + 2]] << 6 | table[str[i + 3]];    }    return ret;}int main(){    init();    cout << int(table[0]) << endl;    string str;    cin >> str;    cout << decode(str) << endl;    return 0;}
    27. 当输入为Y2NmIDIwMjE= 时,输出的第二⾏为( )。
    • A."ccf2021"
    • B."ccf2022"
    • C."ccf 2021"
    • D."ccf 2022"
  28. 28.判断题1.5 分
    阅读以下程序: 判断题正确填 √,错误填 ×。假设输入的x是不超过1000的自然数。
    #include <iostream>using namespace std;const int n = 100000;const int N = n + 1;int m;int a[N], b[N], c[N], d[N];int f[N], g[N];void init(){    f[1] = g[1] = 1;    for (int i = 2; i <= n; i++) {        if (!a[i]) {            b[m++] = i;            c[i] = 1, f[i] = 2;            d[i] = 1, g[i] = i + 1;        }        for (int j = 0; j < m && b[j] * i <= n; j++) {            int k = b[j];            a[i * k] = 1;            if (i % k == 0) {                c[i * k] = c[i] + 1;                f[i * k] = f[i] / c[i * k] * (c[i * k] + 1);                d[i * k] = d[i];                g[i * k] = g[i] * k + d[i];                break;            }            else {                c[i * k] = 1;                f[i * k] = 2 * f[i];                d[i * k] = g[i];                g[i * k] = g[i] * (k + 1);            }        }    }}int main() {    init();    int x;    cin >> x;    cout << f[x] << " " << g[x] << endl;    return 0;}
    28. 若输⼊不为1,把第13⾏删去不会影响输出的结果。( )
  29. 29.判断题2 分
    阅读以下程序: 判断题正确填 √,错误填 ×。假设输入的x是不超过1000的自然数。
    #include <iostream>using namespace std;const int n = 100000;const int N = n + 1;int m;int a[N], b[N], c[N], d[N];int f[N], g[N];void init(){    f[1] = g[1] = 1;    for (int i = 2; i <= n; i++) {        if (!a[i]) {            b[m++] = i;            c[i] = 1, f[i] = 2;            d[i] = 1, g[i] = i + 1;        }        for (int j = 0; j < m && b[j] * i <= n; j++) {            int k = b[j];            a[i * k] = 1;            if (i % k == 0) {                c[i * k] = c[i] + 1;                f[i * k] = f[i] / c[i * k] * (c[i * k] + 1);                d[i * k] = d[i];                g[i * k] = g[i] * k + d[i];                break;            }            else {                c[i * k] = 1;                f[i * k] = 2 * f[i];                d[i * k] = g[i];                g[i * k] = g[i] * (k + 1);            }        }    }}int main() {    init();    int x;    cin >> x;    cout << f[x] << " " << g[x] << endl;    return 0;}
    29. 第25⾏的 f[i] / c[i * k]可能存在⽆法整除⽽向下取整的情况。( )
  30. 30.判断题2 分
    阅读以下程序: 判断题正确填 √,错误填 ×。假设输入的x是不超过1000的自然数。
    #include <iostream>using namespace std;const int n = 100000;const int N = n + 1;int m;int a[N], b[N], c[N], d[N];int f[N], g[N];void init(){    f[1] = g[1] = 1;    for (int i = 2; i <= n; i++) {        if (!a[i]) {            b[m++] = i;            c[i] = 1, f[i] = 2;            d[i] = 1, g[i] = i + 1;        }        for (int j = 0; j < m && b[j] * i <= n; j++) {            int k = b[j];            a[i * k] = 1;            if (i % k == 0) {                c[i * k] = c[i] + 1;                f[i * k] = f[i] / c[i * k] * (c[i * k] + 1);                d[i * k] = d[i];                g[i * k] = g[i] * k + d[i];                break;            }            else {                c[i * k] = 1;                f[i * k] = 2 * f[i];                d[i * k] = g[i];                g[i * k] = g[i] * (k + 1);            }        }    }}int main() {    init();    int x;    cin >> x;    cout << f[x] << " " << g[x] << endl;    return 0;}
    30. 在执⾏完init()后,f数组不是单调递增的,但g数组是单调递增的。( )
  31. 31.单选题3 分
    阅读以下程序: 判断题正确填 √,错误填 ×。假设输入的x是不超过1000的自然数。
    #include <iostream>using namespace std;const int n = 100000;const int N = n + 1;int m;int a[N], b[N], c[N], d[N];int f[N], g[N];void init(){    f[1] = g[1] = 1;    for (int i = 2; i <= n; i++) {        if (!a[i]) {            b[m++] = i;            c[i] = 1, f[i] = 2;            d[i] = 1, g[i] = i + 1;        }        for (int j = 0; j < m && b[j] * i <= n; j++) {            int k = b[j];            a[i * k] = 1;            if (i % k == 0) {                c[i * k] = c[i] + 1;                f[i * k] = f[i] / c[i * k] * (c[i * k] + 1);                d[i * k] = d[i];                g[i * k] = g[i] * k + d[i];                break;            }            else {                c[i * k] = 1;                f[i * k] = 2 * f[i];                d[i * k] = g[i];                g[i * k] = g[i] * (k + 1);            }        }    }}int main() {    init();    int x;    cin >> x;    cout << f[x] << " " << g[x] << endl;    return 0;}
    31. init函数的时间复杂度为( )。
    • A.θ(n)
    • B.θ(nlogn)
    • C.θ(n√n)
    • D.θ(n^2)
  32. 32.单选题3 分
    阅读以下程序: 判断题正确填 √,错误填 ×。假设输入的x是不超过1000的自然数。
    #include <iostream>using namespace std;const int n = 100000;const int N = n + 1;int m;int a[N], b[N], c[N], d[N];int f[N], g[N];void init(){    f[1] = g[1] = 1;    for (int i = 2; i <= n; i++) {        if (!a[i]) {            b[m++] = i;            c[i] = 1, f[i] = 2;            d[i] = 1, g[i] = i + 1;        }        for (int j = 0; j < m && b[j] * i <= n; j++) {            int k = b[j];            a[i * k] = 1;            if (i % k == 0) {                c[i * k] = c[i] + 1;                f[i * k] = f[i] / c[i * k] * (c[i * k] + 1);                d[i * k] = d[i];                g[i * k] = g[i] * k + d[i];                break;            }            else {                c[i * k] = 1;                f[i * k] = 2 * f[i];                d[i * k] = g[i];                g[i * k] = g[i] * (k + 1);            }        }    }}int main() {    init();    int x;    cin >> x;    cout << f[x] << " " << g[x] << endl;    return 0;}
    32. 在执⾏完init()后,f[1], f[2], f[3] ...... f[100]中有( )个等于2。
    • A.23
    • B.24
    • C.25
    • D.26
  33. 33.单选题4 分
    阅读以下程序: 判断题正确填 √,错误填 ×。假设输入的x是不超过1000的自然数。
    #include <iostream>using namespace std;const int n = 100000;const int N = n + 1;int m;int a[N], b[N], c[N], d[N];int f[N], g[N];void init(){    f[1] = g[1] = 1;    for (int i = 2; i <= n; i++) {        if (!a[i]) {            b[m++] = i;            c[i] = 1, f[i] = 2;            d[i] = 1, g[i] = i + 1;        }        for (int j = 0; j < m && b[j] * i <= n; j++) {            int k = b[j];            a[i * k] = 1;            if (i % k == 0) {                c[i * k] = c[i] + 1;                f[i * k] = f[i] / c[i * k] * (c[i * k] + 1);                d[i * k] = d[i];                g[i * k] = g[i] * k + d[i];                break;            }            else {                c[i * k] = 1;                f[i * k] = 2 * f[i];                d[i * k] = g[i];                g[i * k] = g[i] * (k + 1);            }        }    }}int main() {    init();    int x;    cin >> x;    cout << f[x] << " " << g[x] << endl;    return 0;}
    33. 当输⼊1000时,输出为( )。
    • A.15 1340
    • B.15 2340
    • C.16 2340
    • D.16 1340
  34. 34.单选题3 分
    完善以下程序:
    #include <iostream>using namespace std;const int MAXN = 1000000;int F[MAXN];int main() {    int n;    cin >> n;    int i = 0, p = 0, c = 0;    while (①) {        if (F[i] == 0) {            if (②) {                F[i] = 1;                ③;            }            ④;        }        ⑤;    }    int ans = -1;    for (i = 0; i < n; i++)        if (F[i] == 0)            ans = i;    cout << ans << endl;    return 0;}
    34. ①处应填( )
    • A.i < n
    • B.c < n
    • C.i < n - 1
    • D.c < n - 1
  35. 35.单选题3 分
    完善以下程序:
    #include <iostream>using namespace std;const int MAXN = 1000000;int F[MAXN];int main() {    int n;    cin >> n;    int i = 0, p = 0, c = 0;    while (①) {        if (F[i] == 0) {            if (②) {                F[i] = 1;                ③;            }            ④;        }        ⑤;    }    int ans = -1;    for (i = 0; i < n; i++)        if (F[i] == 0)            ans = i;    cout << ans << endl;    return 0;}
    35. ②处应填( )
    • A.i % 2 == 0
    • B.i % 2 == 1
    • C.p
    • D.!p
  36. 36.单选题3 分
    完善以下程序:
    #include <iostream>using namespace std;const int MAXN = 1000000;int F[MAXN];int main() {    int n;    cin >> n;    int i = 0, p = 0, c = 0;    while (①) {        if (F[i] == 0) {            if (②) {                F[i] = 1;                ③;            }            ④;        }        ⑤;    }    int ans = -1;    for (i = 0; i < n; i++)        if (F[i] == 0)            ans = i;    cout << ans << endl;    return 0;}
    36. ③处应填( )
    • A.i++
    • B.i = (i + 1) % n
    • C.c++
    • D.p ^= 1
  37. 37.单选题3 分
    完善以下程序:
    #include <iostream>using namespace std;const int MAXN = 1000000;int F[MAXN];int main() {    int n;    cin >> n;    int i = 0, p = 0, c = 0;    while (①) {        if (F[i] == 0) {            if (②) {                F[i] = 1;                ③;            }            ④;        }        ⑤;    }    int ans = -1;    for (i = 0; i < n; i++)        if (F[i] == 0)            ans = i;    cout << ans << endl;    return 0;}
    37. ④处应填( )
    • A.i++
    • B.i = (i + 1) % n
    • C.c++
    • D.p ^= 1
  38. 38.单选题3 分
    完善以下程序:
    #include <iostream>using namespace std;const int MAXN = 1000000;int F[MAXN];int main() {    int n;    cin >> n;    int i = 0, p = 0, c = 0;    while (①) {        if (F[i] == 0) {            if (②) {                F[i] = 1;                ③;            }            ④;        }        ⑤;    }    int ans = -1;    for (i = 0; i < n; i++)        if (F[i] == 0)            ans = i;    cout << ans << endl;    return 0;}
    38. ⑤处应填( )
    • A.i++
    • B.i = (i + 1) % n
    • C.c++
    • D.p ^= 1
  39. 39.单选题3 分
    完善以下程序:
    #include <iostream>using namespace std;struct point {    int x, y, id;};bool equals(point a, point b) {    return a.x == b.x && a.y == b.y;}bool cmp(point a, point b) {    return ①;}void sort(point A[], int n) {    for (int i = 0; i < n; i++)        for (int j = 1; j < n; j++)            if (cmp(A[j], A[j - 1])) {                point t = A[j];                A[j] = A[j - 1];                A[j - 1] = t;            }}int unique(point A[], int n) {    int t = 0;    for (int i = 0; i < n; i++)        if (②)            A[t++] = A[i];    return t;}bool binary_search(point A[], int n, int x, int y) {    point p;    p.x = x;    p.y = y;    p.id = n;    int a = 0, b = n - 1;    while (a < b) {        int mid = ③;        if (④)            a = mid + 1;        else            b = mid;    }    return equals(A[a], p);}const int MAXN = 1000;point A[MAXN];int main() {    int n;    cin >> n;    for (int i = 0; i < n; i++) {        cin >> A[i].x >> A[i].y;        A[i].id = i;    }    sort(A, n);    n = unique(A, n);    int ans = 0;    for (int i = 0; i < n; i++)        for (int j = 0; j < n; j++)            if (⑤ && binary_search(A, n, A[i].x, A[j].y) &&                binary_search(A, n, A[j].x, A[i].y)) {                ans++;            }    cout << ans << endl;    return 0;}
    39. ①处应填( )
    • A.a.x != b.x ? a.x < b.x : a.id < b.id
    • B.a.x != b.x ? a.x < b.x : a.y < b.y
    • C.equals(a,b) ? a.id < b.id : a.x < b.x
    • D.equals(a,b) ? a.id < b.id : (a.x != b.x ? a.x < b.x : a.y < b.y)
  40. 40.单选题3 分
    完善以下程序:
    #include <iostream>using namespace std;struct point {    int x, y, id;};bool equals(point a, point b) {    return a.x == b.x && a.y == b.y;}bool cmp(point a, point b) {    return ①;}void sort(point A[], int n) {    for (int i = 0; i < n; i++)        for (int j = 1; j < n; j++)            if (cmp(A[j], A[j - 1])) {                point t = A[j];                A[j] = A[j - 1];                A[j - 1] = t;            }}int unique(point A[], int n) {    int t = 0;    for (int i = 0; i < n; i++)        if (②)            A[t++] = A[i];    return t;}bool binary_search(point A[], int n, int x, int y) {    point p;    p.x = x;    p.y = y;    p.id = n;    int a = 0, b = n - 1;    while (a < b) {        int mid = ③;        if (④)            a = mid + 1;        else            b = mid;    }    return equals(A[a], p);}const int MAXN = 1000;point A[MAXN];int main() {    int n;    cin >> n;    for (int i = 0; i < n; i++) {        cin >> A[i].x >> A[i].y;        A[i].id = i;    }    sort(A, n);    n = unique(A, n);    int ans = 0;    for (int i = 0; i < n; i++)        for (int j = 0; j < n; j++)            if (⑤ && binary_search(A, n, A[i].x, A[j].y) &&                binary_search(A, n, A[j].x, A[i].y)) {                ans++;            }    cout << ans << endl;    return 0;}
    40. ②处应填( )
    • A.i == 0 || cmp(A[i], A[i - 1])
    • B.t == 0 || equals(A[i], A[t - 1])
    • C.i == 0 || !cmp(A[i], A[i - 1])
    • D.t == 0 || !equals(A[i], A[t - 1])
  41. 41.单选题3 分
    完善以下程序:
    #include <iostream>using namespace std;struct point {    int x, y, id;};bool equals(point a, point b) {    return a.x == b.x && a.y == b.y;}bool cmp(point a, point b) {    return ①;}void sort(point A[], int n) {    for (int i = 0; i < n; i++)        for (int j = 1; j < n; j++)            if (cmp(A[j], A[j - 1])) {                point t = A[j];                A[j] = A[j - 1];                A[j - 1] = t;            }}int unique(point A[], int n) {    int t = 0;    for (int i = 0; i < n; i++)        if (②)            A[t++] = A[i];    return t;}bool binary_search(point A[], int n, int x, int y) {    point p;    p.x = x;    p.y = y;    p.id = n;    int a = 0, b = n - 1;    while (a < b) {        int mid = ③;        if (④)            a = mid + 1;        else            b = mid;    }    return equals(A[a], p);}const int MAXN = 1000;point A[MAXN];int main() {    int n;    cin >> n;    for (int i = 0; i < n; i++) {        cin >> A[i].x >> A[i].y;        A[i].id = i;    }    sort(A, n);    n = unique(A, n);    int ans = 0;    for (int i = 0; i < n; i++)        for (int j = 0; j < n; j++)            if (⑤ && binary_search(A, n, A[i].x, A[j].y) &&                binary_search(A, n, A[j].x, A[i].y)) {                ans++;            }    cout << ans << endl;    return 0;}
    41. ③处应填( )
    • A.b - (b - a) / 2 + 1
    • B.(a + b + 1) >> 1
    • C.(a + b) >> 1
    • D.a + (b - a + 1) / 2
  42. 42.单选题3 分
    完善以下程序:
    #include <iostream>using namespace std;struct point {    int x, y, id;};bool equals(point a, point b) {    return a.x == b.x && a.y == b.y;}bool cmp(point a, point b) {    return ①;}void sort(point A[], int n) {    for (int i = 0; i < n; i++)        for (int j = 1; j < n; j++)            if (cmp(A[j], A[j - 1])) {                point t = A[j];                A[j] = A[j - 1];                A[j - 1] = t;            }}int unique(point A[], int n) {    int t = 0;    for (int i = 0; i < n; i++)        if (②)            A[t++] = A[i];    return t;}bool binary_search(point A[], int n, int x, int y) {    point p;    p.x = x;    p.y = y;    p.id = n;    int a = 0, b = n - 1;    while (a < b) {        int mid = ③;        if (④)            a = mid + 1;        else            b = mid;    }    return equals(A[a], p);}const int MAXN = 1000;point A[MAXN];int main() {    int n;    cin >> n;    for (int i = 0; i < n; i++) {        cin >> A[i].x >> A[i].y;        A[i].id = i;    }    sort(A, n);    n = unique(A, n);    int ans = 0;    for (int i = 0; i < n; i++)        for (int j = 0; j < n; j++)            if (⑤ && binary_search(A, n, A[i].x, A[j].y) &&                binary_search(A, n, A[j].x, A[i].y)) {                ans++;            }    cout << ans << endl;    return 0;}
    42. ④处应填( )
    • A.!cmp(A[mid], p)
    • B.cmp(A[mid], p)
    • C.cmp(p, A[mid])
    • D.!cmp(p, A[mid])
  43. 43.单选题3 分
    完善以下程序:
    #include <iostream>using namespace std;struct point {    int x, y, id;};bool equals(point a, point b) {    return a.x == b.x && a.y == b.y;}bool cmp(point a, point b) {    return ①;}void sort(point A[], int n) {    for (int i = 0; i < n; i++)        for (int j = 1; j < n; j++)            if (cmp(A[j], A[j - 1])) {                point t = A[j];                A[j] = A[j - 1];                A[j - 1] = t;            }}int unique(point A[], int n) {    int t = 0;    for (int i = 0; i < n; i++)        if (②)            A[t++] = A[i];    return t;}bool binary_search(point A[], int n, int x, int y) {    point p;    p.x = x;    p.y = y;    p.id = n;    int a = 0, b = n - 1;    while (a < b) {        int mid = ③;        if (④)            a = mid + 1;        else            b = mid;    }    return equals(A[a], p);}const int MAXN = 1000;point A[MAXN];int main() {    int n;    cin >> n;    for (int i = 0; i < n; i++) {        cin >> A[i].x >> A[i].y;        A[i].id = i;    }    sort(A, n);    n = unique(A, n);    int ans = 0;    for (int i = 0; i < n; i++)        for (int j = 0; j < n; j++)            if (⑤ && binary_search(A, n, A[i].x, A[j].y) &&                binary_search(A, n, A[j].x, A[i].y)) {                ans++;            }    cout << ans << endl;    return 0;}
    43. ⑤处应填( )
    • A.A[i].x == A[j].x
    • B.A[i].id < A[j].id
    • C.A[i].x == A[j].x && A[i].id < A[j].id
    • D.A[i].x < A[j].x && A[i].y < A[j].y