#2556. 2019 CSP-J1 真题 · 阅读程序2
2019 CSP-J1 真题 · 阅读程序2
2019 CSP-J1 真题(120 分钟,总分 100 分)
阅读程序2(共 6 题,共 12.0 分)
1.
#include <cstdio>
using namespace std;
int n, m;
int a[100], b[100];
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i)
a[i] = b[i] = 0;
for (int i = 1; i <= m; ++i)
{
int x, y;
scanf("%d%d", &x, &y);
if (a[x] < y && b[y] < x)
{
if (a[x] > 0)
b[a[x]] = 0;
if (b[y] > 0)
a[b[y]] = 0;
a[x] = y;
b[y] = x;
}
}
int ans = 0;
for (int i = 1; i <= n; ++i)
{
if (a[i] == 0)
++ans;
if (b[i] == 0)
++ans;
}
printf("%d", ans);
return 0;
}
假设输入的n和m都是正整数,x和y都是在[1, n]的范围内的整数,完成下 面的判断题和单选题:
当m>0时,输出的值一定小于2n。()
{{ select(1) }}
- 正确
- 错误
2. 执行完第27行的"++ans”时,ans一定是偶数。()
{{ select(2) }}
- 正确
- 错误
3. a[i] 和 b[i] 不可能同时大于0。()
{{ select(3) }}
- 正确
- 错误
4. 右程序执行到第13行时,x总是小于y,那么第15行不会被执行。()
{{ select(4) }}
- 正确
- 错误
5. 若m个x两两不同,且m个y两两不同,则输出的值为()
{{ select(5) }}
cpp 2n-2mcpp 2n+2cpp 2n-2cpp 2n
6. 若m个x两两不同,且m个y都相等,则输出的值为()
{{ select(6) }}
cpp 2n-2cpp 2ncpp 2mcpp 2n-2m
相关
在下列比赛中: