1 条题解

  • 1
    @ 2025-03-20 20:07:49

    #include<bits/stdc++.h>//万能头文件
    using namespace std;
    struct go{
    int to, next;
    }edge[100001];//前向星存边
    int Head[100001], n, k, a, cnt, cnt1, ans;
    void add(int xx, int yy);
    int main() {
    scanf("%d%d", &n, &k);//输入
    for (int i = 1; i <= n; i++) {
    Head[i] = -1;
    while (true) {
    scanf("%d", &a);
    if (a == 0) {
    break;
    }
    add(i, a);
    }
    }
    for (int x = 1; x <= n; x++) {
    cnt1 = 0;
    for (int i = Head[x]; i != -1; i = edge[i].next) {
    cnt1++;//记录这个人愿意和多少人交流
    }
    if (cnt1 >= k) {
    ans++;//如果愿意和k个或以上的人交流,答案就+1
    }
    }
    printf("%d", ans);//输出
    return 0;
    }
    void add(int xx, int yy) {
    cnt++;
    edge[cnt].to = yy;
    edge[cnt].next = Head[xx];
    Head[xx] = cnt;
    return;
    }

  • 1

信息

ID
1179
难度
9
分类
贪心 点击显示
标签
递交数
5
已通过
4
通过率
80%
上传者