#86. 树与图第四题(NOIP2018)

树与图第四题(NOIP2018)

第四题(NOIP2018)

#include<cstdio>
int n, d[100];
bool v[100];
int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", d + i);
        v[i] = false;
    }
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (!v[i]) {
            for (int j = i; !v[j]; j = d[j]) {
                v[j] = true;
            }
            ++cnt;
        }
    }
    printf("%d\n", cnt);
    return 0;
}
  1. 【判断题】将第7行的d+i换成&d[i],程序运行不受影响。
    {{ select(1) }}
  • 正确
  • 错误
  1. 【判断题】第12行的!v[i]v[i]==false语句意思一致。
    {{ select(2) }}
  • 正确
  • 错误
  1. 【判断题】程序的输出结果cnt至少等于1。
    {{ select(3) }}
  • 正确
  • 错误
  1. 【判断题】若输入的数组d中有重复的数字,程序会进入死循环。
    {{ select(4) }}
  • 正确
  • 错误
  1. 【选择题】若输入数字为5 1 2 3 4 5,则输出为( )。
    {{ select(5) }}
  • 0
  • 1
  • 2
  • 5
  1. 【选择题】若输入数字为10 7 1 4 3 2 5 9 8 0 6,则输出为( )。
    {{ select(6) }}
  • 3
  • 6
  • 7
  • 8