比赛的时候用vector交集做的。。。情况考虑的不全面 wrong到疯
赛后考虑全了情况。。。。T了 果然 set_intersection 不能相信
嗯 不好意思 交集a了 第二个代码
求出来每个1的交集
为0的时候 要减去相同的元素 看最后一个案例的B和K的输出想想为什么
另一个做法就是处理出每个人名的序列
然后输入序列的时候去找一样的 如果只有一个
那就是它了
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <list>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define rb(a) scanf("%lf", &a)
#define rf(a) scanf("%f", &a)
#define pd(a) printf("%d\n", a)
#define plld(a) printf("%lld\n", a)
#define pc(a) printf("%c\n", a)
#define ps(a) printf("%s\n", a)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff;
int n, q, c, m;
map<string, string> mapp;
map<string, int> mapp2;
string str[maxn];
int main()
{
int T;
rd(T);
while(T--)
{
rd(n), rd(q);
rd(c);
mapp.clear();
string name;
for(int i = ; i < c; i++)
{
cin >> str[i];
}
for(int i = ; i <= q; i++)
{
rd(m);
mapp2.clear();
for(int j = ; j < m; j++)
{
cin >> name;
mapp[name] += "";
mapp2[name] = ;
}
for(int j = ; j < c; j++)
{
if(!mapp2[str[j]])
mapp[str[j]] += "";
if(i != q)
mapp[str[j]] += " ";
}
}
getchar();
string str1, str2;
for(int i = ; i <= n; i++)
{
int cnt = ;
getline(cin, str1);
for(int j = ; j < c; j++)
{
if(mapp[str[j]] == str1)
cnt++, str2 = str[j];
}
if(cnt == )
cout << str2 << endl;
else
printf("Let's go to the library!!\n"); } } return ;
}
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <list>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define rb(a) scanf("%lf", &a)
#define rf(a) scanf("%f", &a)
#define pd(a) printf("%d\n", a)
#define plld(a) printf("%lld\n", a)
#define pc(a) printf("%c\n", a)
#define ps(a) printf("%s\n", a)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff; vector<string> G[maxn];
int n, q, c, m;
vector<string> v, v1;
int main()
{
int T;
rd(T);
while(T--)
{
rd(n), rd(q);
rd(c);
for(int i = ; i <= q + ; i++) G[i].clear();
string name;
for(int i = ; i < c; i++)
{
cin >> name;
G[].push_back(name);
}
sort(G[].begin(), G[].end());
for(int i = ; i <= q; i++)
{
rd(m);
for(int j = ; j < m; j++)
cin >> name, G[i].push_back(name);
sort(G[i].begin(), G[i].end());
}
for(int i = ; i <= n; i++)
{
v.clear();
v = G[];
int ans = ;
for(int j = ; j <= q; j++)
{
int tmp;
rd(tmp);
if(tmp == )
{
ans++; set_intersection(v.begin(), v.end(), G[j].begin(), G[j].end(), back_inserter(v1));
v.clear();
v = v1;
v1.clear(); sort(v.begin(), v.end());
}
else
{
set_intersection(v.begin(), v.end(), G[j].begin(), G[j].end(), back_inserter(v1));
for(int k = ; k < v1.size(); k++)
{
v.erase(find(v.begin(), v.end(), v1[k]));
}
v1.clear();
}
}
if(v.size() == )
{
cout << v[] << endl;
}
else
{
printf("Let's go to the library!!\n"); } }
} return ;
}