Test instructions
n items each item has a maximum of 4 properties m Times asked to ask up to 4 properties output number of items containing these attributes
Ideas:
If the property of an item is a B c D then it can contribute to the following query to make a, B, C, D, AB, AC, AD, BC, BD, CD, ABC, ABD, ACD, BCD, ABCD then only need to each item to contribute to the query + + can notice to keep the ABCD is orderly arrangement
And then it's a map. The number of hash of the string and then the combination of the number of the scheme record scheme
Code:
#include <cstdio> #include <iostream> #include <cstring> #include <string> #include < algorithm> #include <map> #include <set> #include <vector> #include <queue> #include < cstdlib> #include <ctime> #include <cmath> #include <bitset>using namespace Std;typedef unsigned Long long LL; #define SEED 133331ULLint N; LL id;map<string, ll> fzc;map<ll, int> ans1;map<ll, int> ans2;map<ll, int> Ans3;map<LL, int& Gt ANS4; LL a[5];string Str;int Main () {int I, j, K, F1, F2, f3, F4;id = 1;cin >> n;for (i = 0; i < n; i++) {cin >> K;for (j = 0; J < K; J + +) {cin >> str;if (fzc[str] = = 0) Fzc[str] = id++;a[j] = Fzc[str];} if (k > 1) sort (A, a + K), for (f1 = 0; F1 < K; f1++) {ans1[a[f1]]++;if (K->= 2) {for (F2 = f1 + 1; F2 < K; f2++ {ANS2[A[F1] * seed + a[f2]]++;if (k >= 3) {for (F3 = F2 + 1; f3 < K; f3++) {ans3[(a[f1] * seed + A[F2]) * seed + A [F3]] ++;if (k >= 4) {for (F4 = f3 + 1; F4 &Lt K f4++) ans4[((a[f1] * seed + A[F2]) * seed + a[f3]) * seed + a[f4]]++;}}}}}} CIN >> N;while (n--) {cin >> k;for (j = 0; J < K; J + +) {cin >> str;if (!fzc.count (str)) a[j] = 0;elsea [j] = Fzc[str];} for (j = 0; J < K; J + +)//printf ("%llu", A[j]),//cout << ((a[0] * seed + a[1]) * seed + a[2]) * seed + a[3] < ;< endl;//printf ("\ n"), if (K > 1) sort (A, a + K), if (a[0] = = 0) {cout << 0 << endl;continue;} if (k = = 1) cout << ans1[a[0]] << endl;else if (k = = 2) cout << ans2[a[0] * seed + a[1]] << endl;els e if (k = = 3) cout << ans3[(a[0] * seed + a[1]) * seed + a[2]] << endl;elsecout << ans4[((a[0] * seed + A [1]) * seed + a[2]) * seed + a[3]]<< Endl;} cout << (*ans4.begin ()). First << "" << (*ans4.begin ()). Second << Endl;return 0;}
SGU 552 Database Optimization