#ACSP1010. cspj-模拟题10

cspj-模拟题10

普及组CSP-J2024 初赛模拟卷10

一、单项选择题(共15题,每题2分,共计30分;每题有且仅有一个正确选项)

  1. 用C++语言将一个大写字母转换为对应的小写字母(比如将大写字母 A 转换为小写字母a),以下哪个代码不正确?({{ select(1) }})
  • c+=32
  • c-=32
  • c^=' '
  • c^=32
  1. 下列说法中错误的是({{ select(2) }})。
  • 栈、队列、树和图都属于数据结构的范畴
  • CSP-J/CSP-S 是中国计算机学会举办的程序设计竞赛
  • 背包问题属于动态规划算法中的一种类型
  • 按照分布的地理范围,计算机网络类型可以分为星形、环形和总线型
  1. 下列C++数组的定义中,会丢失数据的是({{ select(3) }})。
  • char str1[] = {'C','S','P'};
  • int num1[] = {3,6,9};
  • char str2[] = {'CSP-J','CSP-S','NOIP'};
  • float num2[] = {1.0,3.0,5.0};
  1. 执行下面的C++代码,输出是({{ select(4) }})。
    #include<bits/stdc++. h>
    using namespace std;
    int main() {
        int tmp = 1;
        for(int i=1; i<10; i++)
            for(int j=1; j<5; j++)
                if(i%j == 1)
                   tmp++;
        cout<<tmp;
        return 0;
    }
    
  • 10
  • 11
  • 12
  • 13

5.24位真彩色能表示({{ select(5) }})种颜色。

  • 16 777216
  • 256
  • 24
  • 65536

6.以下哪个不属于STL 中队列(queue) 的操作函数?({{ select(6) }})

  • push
  • pop
  • empty
  • top

7.归并排序算法的空间复杂度是({{ select(7) }})。

  • O(logn)
  • O(n)
  • O(1)
  • O(nlogn)

8.下列C++代码执行后不能输出"NOIP"的是({{ select(8) }})。

  • string s("NOIP"); cout<<s<<endl;
  • string s="NOIP"; cout<<s<<endl;
  • string s("NOIP"); cout<<s[1]<<s[2]<<s[3]<<s[4]<<endl;
  • string s{"NOIP"}; cout<<s<<endl;

9.哈夫曼树的构造用到了({{ select(9) }})的算法思想。

  • 二分查找
  • 搜索回溯
  • 贪心
  • 动态规划

10.在C++语言中, 32位系统一个字符指针变量 char *p占({{ select(10) }})字节。

  • 1
  • 2
  • 8
  • 4

11.某数列有 2024个各不相同的单元,由低至高按序排列。现要对该数列进行二分搜索(binary search )。在最坏情况下, 需搜索({{ select(11) }})个单元。

  • 2024
  • 11
  • 12
  • 1012

12.在C++程序中,判断a不等于0且b不等于0且c不等于0的正确的条件表达式是({{ select(12) }})。

  • !((a!=0) | | (b!=0) || (c!=0))
  • !((a!=0) && (b!=0) && (c!=0))
  • a && b && c
  • (a=0) && (b=0) && (c=0)

13.某二叉树有4个结点,则该二叉树的不同形态有({{ select(13) }})种。

  • 12
  • 14
  • 10
  • 16

14.设含有 8 个元素的集合的全部子集数为 S,其中由 6个元素组成的子集数为T,则T/S的值为({{ select(14) }})。

  • 7/16
  • 7/64
  • 7/32
  • 21/256

15.对于给定的序列{aₖ}, 我们把(i,j)称为逆序对, 当且仅当i<j且ai>aja_i>a_j,那么序列1,9,2,4,8,6的逆序对有({{ select(15) }})个。

  • 7
  • 6
  • 5
  • 4

二、阅读程序(程序输入不超过数组或字符串定义的范围;判断题正确填✔,错误填×;除特殊说明外,判断题每题1.5分,选择题每题3分,共计40分)

(1)

#include<bits/stdc++. h>
using namespace std;
int a[10];
void print_num(){
    cout<<'1';
    for(int i=2;i<=9;++i){
        if(a[i]==0)
            cout<<'+';
        else
            cout<<'-';
        cout<<i;
    }
    cout<<"=9"<<endl;
    return;
}
int main(){
    for(int i=0; i<=255; i++){
        int k=i, s = 1;
        for(int j=9;j>=2;j--){
            if(k&1){
                s-=j;
                a[j]=1;
            }
            else{
                s+=j;
                a[j]=0;
            }
            k>>=1;
        }
        if(s==9)
            print_num();
    }
    return 0;
}

判断题

16.将第8行和第10行交换,程序的运行结果不会改变。({{ select(16) }})

  • 正确
  • 错误

17.将第8行中的'+'改为"+",程序的运行结果不会改变。({{ select(17) }})

  • 正确
  • 错误

18.将第20行中的k&1改为k%2,程序的运行结果不会改变。({{ select(18) }})

  • 正确
  • 错误

19.将第28行中的k>>=1改为k/=2, 程序的运行结果不会改变。({{ select(19) }})

  • 正确
  • 错误

选择题

20.输出数据共有({{ select(20) }})行。

  • 11
  • 10
  • 12
  • 13

21.程序主要用到了({{ select(21) }})的算法思想。

  • 贪心
  • 二分
  • 二进制
  • 动态规划

(2)

#include<bits/stdc++. h>
using namespace std;
stack <char> s;
int main()
{
    string a;
    int len, mid, next, top;
    getline(cin,a);
    len=a. length();
    mid=len/2-1;
    for(int i=0; i<=mid; i++)
        s. push(a[i]);
    if(len%2==0)
        next=mid+1;
    else
        next=mid+2;
    for(int i=next;i<=len-1;i++)
    {
        if(a[i] != s.top())
            break;
        s. pop();
    }
    if(s.size()==0)
        cout<<"yes";
    else
        cout<<"no";
    return 0;
}

判断题

22.将第6行中的string a改为char a[256], 程序的输出结果不变。({{ select(22) }})

  • 正确
  • 错误

23.即使输入的字符串中间有空格,getline函数也支持相应的处理。({{ select(23) }})

  • 正确
  • 错误

24.将第 11行中的int i=0改为 int i=1, 程序的输出结果不变。({{ select(24) }})

  • 正确
  • 错误

25.若输入abc cba, 同时将第8行的getline(cin,a)改为 cin>>a, 程序的输出结果为 no。({{ select(25) }})

  • 正确
  • 错误

选择题

26.若输出结果为yes,则输入可能为({{ select(26) }})。

  • abc big abc
  • abc big big cba
  • abc big gib abc
  • abc big gib cba

27.若输出结果为no,则输入可能为({{ select(27) }})。

  • 1234567890987654321
  • 12345 6789899876 54321
  • 12345 678909876 54321
  • 12345 6789009876 54321

(3)

#include<bits/stdc++. h>
using namespace std;
struct node
{
    int data;
    node *next;
};
int n,m;
node *head,*p,*r;
int main()
{
    cin >> n >> m;
    head = new node;
    head->data = 1;
    head->next = NULL;
    r = head;
    for(int i=2;i<=n;i++)
    {
        p = new node;
        p->data = i;
        p->next = NULL;
        r->next = p;
        r = p;
    }
    r->next = head;
    r = head;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m-2;j++)
            r = r->next;
        cout<<r->next->data<<" ";
        r->next = r->next->next;
        r = r->next;
    }
    return 0;
}

判断题

28.node这个结构体在内存空间中占 8 字节。({{ select(28) }})

  • 正确
  • 错误

29.程序中有new却没有做delete,输入n大于10必然会导致程序运行时崩溃。({{ select(29) }})

  • 正确
  • 错误

30.若输入为8 5,去掉第15行,程序的运行结果不会改变。({{ select(30) }})

  • 正确
  • 错误

31.本程序用到了双向链表的技巧。({{ select(31) }})

  • 正确
  • 错误

选择题

32.若输入为8 5, 则输出是({{ select(32) }})。

  • 5 2 7 8 1 4 6 3
  • 5 2 8 7 1 4 6 3
  • 5 2 8 7 4 1 6 3
  • 5 2 8 7 1 4 3 6

33.若输入为11 4, 则输出是({{ select(33) }})。

  • 4 8 1 6 11 7 3 2 5 10 9
  • 4 8 6 1 11 7 3 2 5 10 9
  • 4 8 1 11 6 7 3 2 5 10 9
  • 4 8 1 6 11 7 2 3 5 10 9

三、完善程序(单选题,每小题3分,共计30分) (1) 交叉字符串问题。

#include <bits/stdc++. h>
using namespace std;
string str1,str2, str;
bool pos;
int vis[205][205];
void dfs(int s1, int s2, int s){
    if(s1==str1. length() && s2==str2. length()){
        ①;
        return;
    }
    if(②)
        return;
    if(③)
        return;
    vis[s1][s2]=1;
    if(str1[s1]==str[s])
        ④;
    if(str2[s2]==str[s])
        dfs(s1+1,s2+1,s+1);
}
int main(){
    int t,n;
    cin>>t;
    while(t--){
        cin>>str1>>str2>>str;
        ⑤;
        memset(vis,0, sizeof(vis));
        dfs(0,0,0);
        if(pos)
            cout<<"yes"<<endl;
        else
            cout<<"no"<<endl;
    }
    return 0;
}

35.①处应填({{ select(35) }})。

  • pos=true
  • pos=false
  • vis[s1][s2]=1
  • vis[s1][s2]=0

36.②处应填({{ select(36) }})。

  • str1[s1]==str[s] && str2[s2]!=str[s]
  • str1[s1]!=str[s] && str2[s2]!=str[s]
  • str1[s1]!=str[s] || str2[s2]==str[s]
  • str1[s1]==str[s] && str2[s2]==str[s]

37.③处应填({{ select(37) }})。

  • vis[s1][s2]
  • vis[s1][s2]==0
  • pos==true
  • pos==false

38.④处应填({{ select(38) }})。

  • dfs(s1,s2,s+1)
  • dfs(s1+1,s2+1,s)
  • dfs(s1+1,s2,s+1)
  • dfs(s1+1,s2+1,s+1)

39.⑤处应填({{ select(39) }})。

  • vis[s1][s2]==1
  • vis[s1][s2]==0
  • pos==true
  • pos==false

(2) 合并沙子问题。

#include <bits/stdc++. h>
using namespace std;
int main()
{
    int a[105],s[105],f[100][100];
    int j,n,p,m;
    cin>>n;
    s[0]=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        ①;
        f[i][i]=0;
    }
    for(p=1;p<=n-1;p++)
        for(int i=1;i<n;i++)
        {
            ②;
            if(j<=n)
            {
                m=INT_MAX;
                for(int k=i;k<j;k++)
                    m=min(m,③);
                ④;
            }
        }
    cout<<⑤;
    return 0;
}

40.①处应填({{ select(40) }})。

  • s[i]=s[i-1]+a[i-1]
  • s[i]=s[i-1]+a[i]
  • s[i]=s[i-1]+a[i+1]
  • s[i]=min(s[i-1],a[i])

41.②处应填({{ select(41) }})。

  • j=i+p
  • j=i+p-1
  • j=i+p+1
  • j=max(i,p)

42.③处应填({{ select(42) }})。

  • f[i][k] + f[k+1][j]
  • f[i][k] + f[k][j]
  • f[i][k-1] + f[k+1][j]
  • f[i][k+1] + f[k+1][j]

43.④处应填({{ select(43) }})。

  • f[i][j] = m + s[j] - s[i]
  • f[i][j] = m + s[j] - s[i-1]
  • f[i][j] = m + s[j-1] - s[i]
  • f[i][j] = m + s[j-1] - s[i-1]

44.⑤处应填({{ select(44) }})。

  • f[0][n]
  • f[0][n-1]
  • f[1][n]
  • f[1][n-1]