奶牛体操

题目 奶牛体操

image-e1525b76

思路分析

image-bf280668

代码实现

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'

unordered_map<string,int> cnt;
const int N = 30;
int a[N];

int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int k,n;cin>>k>>n;
    for(int i=0;i<k;i++){
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                // cout<<a[i]<<" "<<a[j]<<endl;
                string key = to_string(a[i]) + " " + to_string(a[j]);
                cnt[key]++;
            }
        }
    }
    int ans=0;
    for(auto x:cnt){
        // cout<<x.first<<" "<<x.second<<endl;
        if(x.second==k)    ans++;
    }
    cout<<ans;
    return 0;
}

同类题型

视频讲解


⬅️ 哞叫时间2 🏠 00-刷题理模型 ➡️ 奶牛体检