跳到正文

题解

题解:AT_past202104_c 携帯電話の購入

Crimson_Sky约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年3月14日
篇幅
约 2 分钟

版本

  1. v1当前

AT_past202104_c 携帯電話の購入 题解

洛谷传送门

AT 传送门

思路

输入手机型号数量 NN 和总频段数 MM。接着输入每个手机支持的频段,并存储在 aa 数组中,以便快速查询。

对于每个手机型号,检查其支持的频段是否满足用户需求,统计符合条件的型号数量。

代码

C++
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<bool>> a(n,vector<bool>(m,false));
    for(int i=0;i<n;i++){
        int k;
        cin >> k;
        for(int j=0;j<k;j++){
            int c;
            cin >> c;c--;
            a[i][c]=true;
        }
    }
    int p,q;
    cin >> p >> q;
    vector<int> b(p);
    for(int i=0;i<p;i++){cin >>b[i];b[i]--;}
    int ans=0;
    for(int i=0;i<n;i++){
        int cnt=0;
        for(int j=0;j<p;j++){
            cnt+=a[i][b[j]];
        }
        ans+=(cnt>=q);
    }
    cout << ans << endl;
    return 0;
}
原文