csppass
连续 00 XP登录 / 注册
201924判断题贪心算法普及/提高

程序(二):a[i]和b[i]是否不可能同时大于0

题目

阅读下面的程序,回答问题。 #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; } 判断题:a[i]和b[i]不可能同时大于0。( )

考点拆解
程序阅读与结果判断
易错提醒
阅读程序题要按变量变化顺序手推,不要跳步
选择题要检查单位、边界和题目中的否定词