初赛模拟1
cjn1122334 · · 个人记录
跨年赛初赛试题
第一大题:单项选择题,每题20分,共15题:
-
**注:$\bigoplus$ 为按位异或运算** A. $16 B.
17 C.
18 D.
19 -
int 类型的单个变量可以表示的区间为:( )
A.
0 2147483647 B.
0 2147483648 C.
-2147483648 2147483647 D.
-2147483647 2147483648 -
以下哪个序列对应数字
0 至8 的4 位二进制格雷码(Gray code)?( )A. 0000, 0001, 0011, 0010, 0110, 0111, 0101, 1000
B. 0000, 0001, 0011, 0010, 0110, 0111, 0100, 0101
C. 0000, 0001, 0011, 0010, 0100, 0101, 0111, 0110
D. 0000, 0001, 0011, 0010, 0110, 0111, 0101, 0100
-
以下哪个不是 C++ 中的基本数据类型?( )
A. int
B. float
C. char
D. struct
-
假设有序表中有
n 个元素,则用二分法查找X 的时间复杂度为?( )A.
\Theta(n \ log \ n) B.
\Theta(\sqrt n) C.
\Theta(n) D.
\Theta(log \ n) -
在无向图中,所有顶点的度数之和等于( )。
A. 图的边数的两倍
B. 图的边数
C. 图的顶点数
D. 图的顶点数的两倍
-
给定一个空队列与空栈,每次出栈的时候都会将元素放入入队列里,若执行如下操作:
A入栈、B入栈、C入栈、出栈、出栈、D入栈、出栈,则最后队列里面有元素:( )A.
D,CB.
B,C,DC.
D,C,BD.
C,B,D -
C++ 是面向对象的一种语言,以下不属于 C++ 面向对象 的特性的是:( )
A. 封装
B. 汇编
C. 继承
D. 多态性
-
若一个二叉树的后序遍历为
[D,F,C,E,G,B,A] ,其中序遍历为[D,C,F,A,E,B,G] ,其前序遍历为:()A.
[A,C,D,F,B,E,G] B.
[A,C,B,D,F,E,G] C.
[G,E,F,D,C,B,A] D.
[A,B,F,D,C,G,E] -
5 个小朋友并排站成一列,其中有两个小朋友是双胞胎,如果要求这两个双胞胎必须相邻,则有( )种不同排列方法?
A. 48
B. 36
C. 24
D. 72
-
在 C++ 中,以下哪个函数调用会造成栈溢出?( )
A.
int foo() { return 0; }B.
int bar() { int x = 1; return x; }C.
void baz() { int a[1000]; baz(); }D.
void qux() { return; } -
对于一个整数
n ,定义f(n) 为n 的各位之和,问使f(f(x)) = 10 的最小自然数x 是多少?A. 29
B. 39
C. 199
D. 1999
-
线性表若采用链表存储结构,要求内存中可用存储单元地址( )。
A. 必须连续
B. 部分地址必须连续
C. 一定不连续
D. 连续不连续均可
-
具有
n 个顶点,m 条边的图采用邻接表存储结构,进行深度优先遍历和广度优先遍历运算的时间复杂度均为( )。A.
\Theta((n + m) \ log \ m) A.
\Theta(n + m) C.
\Theta(nm) D.
\Theta(\min(n,m)) -
给出以下代码,求输出( ):
#include <iostream>
using namespace std;
void fun(char *a, char *b) {
a = b;
(*a)++;
}
int main() {
char c1, c2, *p1, *p2;
c1 = 'A';
c2 = 'a';
p1 = &c1;
p2 = &c2;
fun(p1, p2);
cout << c1 << c2 << endl;
return 0;
}
A. Ab
B. Aa
C. Bb
D. ab
二:阅读程序,判断题正确选 T,错误选 F,共计400分
阅读第一篇程序,回答
#include<bits/stdc++.h>
using namespace std;
struct line{
int be;
int en;
};
line d[2000005];
bool cmp(line x,line y){
return x.en<y.en;
}
int cnt=1,pos;
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d%d",&d[i].be,&d[i].en);
sort(d,d+n,cmp);
pos=d[0].en;
for(int i=1;i<n;i++){
if(d[i].be>=pos){
cnt++;
pos=d[i].en;
}
}
printf("%d\n",cnt);
return 0;
}
判断题
-
若删除第 16 行的排序,本算法的结果不会改变( )。10分
-
若输入为:
3 0 2 2 4 1 3,代码会输出2( )。10分 -
本题的排序是按照 en 的大小升序排序的( )。10分
选择题
-
本代码的时间复杂度为( )30分
A.
\Theta(n \ log \ n) B.\Theta(n) C.\Theta(n^2) D.\Theta(n \sqrt n) -
本代码所求为( )30分
A. 最长不重复线段
B. 最多不重复线段
C. 最大覆盖线段长度
D. 最小覆盖线段长度
-
本代码的算法核心是( )30分
A. 贪心 B. 二分 C. 动态规划 D. 枚举
阅读第二篇程序,并回答
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[1919810],dp[1919810];
int n,len;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
if(a[i]>dp[len]) dp[++len]=a[i];
else{
int g=lower_bound(dp+1,dp+len+1,a[i])-dp;
dp[g]=a[i];
}
}
cout<<len<<"\n";
return 0;
}
判断题
-
将第 14 行中的
lower_bound换成upper_bound程序的输出不会改变( )。10分 -
将第 12 行中的
a[i]>dp[len]换成a[i]>=dp[len]程序的输出不会改变( )。10分 -
若程序输入为
6 1 2 4 1 3 4则其输出为6( )。10分
选择题
-
若程序输入的
a 为100 \sim 1 ,则其输出:( )30分A. 0
B. 99
C. 100
D. 1
-
若程序输入皆为 1 (
n \leq 10^6 ),则其输出为( )30分A. 0
B. 99
C. 1
D. 100
-
该程序的时间复杂度为( )30分
A.
\Theta(n \ log \ n) B.\Theta(n) C.\Theta(n^2) D.\Theta(n \sqrt n)
阅读第三道程序,并回答
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define qck ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define N 1919810
using namespace std;
struct edge{
int l;
int r;
int u;
};
int n,m,fa[N],siz[N],ans,cnt;
edge e[N];
bool cmp(edge a,edge b){
return a.u<b.u;
}
int fin(int x){
if(x==fa[x]) return x;
fa[x]=fin(fa[x]);
return fa[x];
}
void merge(int x,int y){
int _x=fin(x);
int _y=fin(y);
if(_x==_y) return;
if(siz[_x]>siz[_y]) swap(_x,_y);
fa[_x]=_y;
siz[_y]+=siz[_x];
}
void init(){
for(int i=1;i<=n;i++){
fa[i]=i;
siz[i]=1;
}
}
signed main(){
qck;
cin>>n>>m;
init();
for(int i=1;i<=m;i++) cin>>e[i].l>>e[i].r>>e[i].u;
sort(e+1,e+m+1,cmp);
for(int i=1;i<=m;i++){
if(fin(e[i].l)!=fin(e[i].r)){
merge(fin(e[i].l),fin(e[i].r));
ans+=e[i].u;
cnt++;
if(cnt==n-1) break;
}
}
if(cnt==n-1) cout<<ans<<"\n";
else cout<<"orz\n";
return 0;
}
判断题
-
此为 Prim 算法最小生成树( )10分
-
删去第 41 行的排序会改变程序输出( )15分
-
orz仅会在改图不连通时输出( )15分
选择题
-
代码43行中的操作是( )30分
A. 判断该边的权值是否超界
B. 判断该边是否可以加入生成树
C. 判断该点是否已经遍历过
D. 优化时间复杂度
-
若删去第三十九行,会发生( )30分
A. 无法正确判断该边是否可以加入生成树,导致答案错误。
B. 无法生成最小的生成树,不是最优解。
C. 无任何影响。
D. 编译错误。
-
该算法的平均时间复杂度(不计算并查集的
\alpha 函数)是( )30分A.
\Theta(n+ \ log \ m) B.
\Theta(nm) C.
\Theta(n^2) D.
\Theta(m \ log \ m) -
该算法的核心算法是( )30分
A. 动态规划
B. 贪心
C. 分治
D. 模拟
三:完善程序,每题30分
阅读程序一,完成
题目描述
C 城可以视为由
小 A 的学校坐落在 C 城的编号为
输入格式
第一行,四个正整数
接下来
接下来
输出格式
共
说明/提示
保证
源程序:
#include<bits/stdc++.h>
#define ll long long
#define N 1919810ll
#define Mod 998244353ll
#define inf 1e9+5ll
#define ima INT_MAX
#define imi INT_MIN
#define lma LONG_LONG_MAX
#define lmi LONG_LONG_MIN
#define pii pair<int,int>
#define qck ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
struct z{
ll to;
ll l;
};
bool operator<(const z &a,const z &b){
return /*第一处*/;
}
vector<z> e[N];
ll d[N],vis[N];
ll n,m,p,op;
void dijkstra(int s){
priority_queue<z> q;
for(ll i=1;i<=n;i++) d[i]=/*第二处*/,vis[i]=0;
d[s]=0;
q.push({s,0});
while(!q.empty()){
z now=q.top(); q.pop();
if(vis[now.to]) continue;
vis[now.to]=true;
for(auto x:e[now.to]){
if(/*第三处*/){
/*第四处*/
}
}
}
}
int main(){
qck;
cin>>n>>m>>p>>op;
for(ll i=1;i<=m;i++){
ll x,y,z;
cin>>x>>y>>z;
e[x].push_back({y,z});
e[y].push_back({x,z});
}
dijkstra(/*第五处*/);
for(ll i=1;i<=op;i++){
ll x;
cin>>x;
cout<<d[x]<<"\n";
}
return 0;
}
-
A.
a.l>b.lB.a.l<b.lC.a.l<=b.lD.a.l!=b.l -
A.
lmaB.lmiC.imaD.imi
A. d[x.to]<=d[now.to]+x.l B. d[x.to]>d[now.to]+x.l
C. d[x.to]<=d[now.to] D. d[x.to]>d[now.to]
-
A.
d[x.to]=d[now.to]; q.push({x.to,d[x.to]});B.
d[now.to]=d[x.to]+x.l; q.push({x.to,d[x.to]});C.
d[x.to]=d[now.to]+x.l; q.push({x.to,d[x.to]});D.
d[now.to]=d[x.to]; q.push({x.to,d[x.to]}); -
A.
opB.pC.nD.m
阅读程序二,完成
题目描述
小刚在玩 JSOI 提供的一个称之为“建筑抢修”的电脑游戏:经过了一场激烈的战斗,T 部落消灭了所有 Z 部落的入侵者。但是 T 部落的基地里已经有
说明/提示
对于
源程序
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct build{
int u1;
int u2;
};
build a[200005];
int n,sum;
priority_queue<int> qu;
bool cmp(build x,build y){
return /*第一处*/;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i].u1>>a[i].u2;
int ti=0;
/*第二处*/
for(int i=1;i<=n;i++){
/*第三处*/
if(/*第四处*/){
sum++;
}else{
/*第五处*/
}
}
cout<<sum;
return 0;
}
-
A.
x.u1<y.u1B.x.u1>y.u1C.x.u2<y.u2D.x.u2>y.u2
A. sort(a+1,a+n+1,cmp);
B. sort(a+1,a+n+1);
C. sort(a,a+n,cmp);
D. sort(a,a+n);
A.
ti+=a[i].u1;
qu.push(a[i].u1);
B.
ti+=a[i].u2;
qu.push(a[i].u2);
C.
ti+=a[i].u1;
D.
ti+=a[i].u2;
-
A.
ti<=a[i].u2B.ti>a[i].u2C.ti>a[i].u1D.ti>=a[i].u1
A.
ti+=qu.top();
qu.pop();
B.
ti-=qu.top();
qu.pop();
C.
ti+=qu.top();
D.
ti-=qu.top();
请使用如下格式做答:
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin>>n;//数据里提供的需要查询的题号
switch(n){
case 1://题号
cout<<"A\n";//第一题答案,代表第六题的选项是A
break;
case 2:
cout<<"B\n";//第二题答案,代表第六题的选项是B
break;
case 3:
cout<<"C\n";//第三题答案,代表第六题的选项是C
break;
case 4:
cout<<"D\n";//第四题答案,代表第四题的选项是D
break;
case 5:
cout<<"T\n";//第五题答案,代表第五题的答案是对
break;
case 6:
cout<<"F\n";//第六题答案,代表第六题的答案是错
break;
//......
}
return 0;
}