比赛的时候用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 ", a) #define plld(a) printf("%lld ", a) #define pc(a) printf("%c ", a) #define ps(a) printf("%s ", 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 = 1100, 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 = 0; i < c; i++) { cin >> str[i]; } for(int i = 1; i <= q; i++) { rd(m); mapp2.clear(); for(int j = 0; j < m; j++) { cin >> name; mapp[name] += "1"; mapp2[name] = 1; } for(int j = 0; j < c; j++) { if(!mapp2[str[j]]) mapp[str[j]] += "0"; if(i != q) mapp[str[j]] += " "; } } getchar(); string str1, str2; for(int i = 1; i <= n; i++) { int cnt = 0; getline(cin, str1); for(int j = 0; j < c; j++) { if(mapp[str[j]] == str1) cnt++, str2 = str[j]; } if(cnt == 1) cout << str2 << endl; else printf("Let's go to the library!! "); } } return 0; }
#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 ", a) #define plld(a) printf("%lld ", a) #define pc(a) printf("%c ", a) #define ps(a) printf("%s ", 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 = 1100, 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 = 0; i <= q + 1; i++) G[i].clear(); string name; for(int i = 0; i < c; i++) { cin >> name; G[0].push_back(name); } sort(G[0].begin(), G[0].end()); for(int i = 1; i <= q; i++) { rd(m); for(int j = 0; j < m; j++) cin >> name, G[i].push_back(name); sort(G[i].begin(), G[i].end()); } for(int i = 1; i <= n; i++) { v.clear(); v = G[0]; int ans = 0; for(int j = 1; j <= q; j++) { int tmp; rd(tmp); if(tmp == 1) { 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 = 0; k < v1.size(); k++) { v.erase(find(v.begin(), v.end(), v1[k])); } v1.clear(); } } if(v.size() == 1) { cout << v[0] << endl; } else { printf("Let's go to the library!! "); } } } return 0; }