B. Gardener and the Array
思路:只要找到一个c他的每一位均在除了它的集合中出现过即可
这题T了2发,用来multiset,注意multiset大的时间复杂度是O(K + logn)k是相同元素的个数,能用map尽量用map
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
void solve()
{
int n; scanf("%d", &n);
vector<int>a[n + 1];
map<int, int>cnt;
for(int i = 1; i <= n; ++ i)
{
int k;
scanf("%d", &k);
a[i].push_back(k);
for(int j = 0; j < k; ++ j)
{
int x; scanf("%d", &x);
a[i].push_back(x);
cnt[x] ++;
}
}
for(int i = 1; i <= n; ++ i)
{
int k = a[i][0];
for(int j = 1; j <= k; ++ j)
{
if(cnt[a[i][j]] < 2) break;
if(j == k && cnt[a[i][j]] >= 2)
{
printf("Yes\n");
return;
}
}
}
printf("No\n");
}
int main()
{
// freopen("1.in", "r", stdin);
int t; scanf("%d", &t);
while(t --) solve();
return 0;
}
标签:int,scanf,CF,solve,printf,Array,Gardener
From: https://www.cnblogs.com/cxy8/p/17398418.html