标签:class 压缩 const 进制 pen close space splay turn
H. Hamburgers 二进制压缩&枚举操作
#include<cstdio> #include<cstring> #include<vector> using namespace std; const int N = 55555; int n, m, i, j, k, x, ans[N], mx[N], b[N]; vector<int>a[N]; bool v[(1 << 26) + 5]; inline int get() //!!!!二进制压缩 把每个人的口味压缩成1<<26内的数 { static char s[1000]; scanf("%s", s); int t = 0, len = strlen(s); for (int i = 0; i < len; i++) { t |= 1 << (s[i] - ‘a‘); //!!!!!!转换成二进制 } return t; } inline void make(int x, int y) { for (int i = x; i; i = (i - 1)&x) //!!!!枚举每位1存在或不存在的情况 { v[i] = y; } } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d", &k); while (k--) { x = get(); a[i].push_back(x); } ans[i] = 1; } scanf("%d", &m); for (i = 1; i <= m; i++) { scanf("%d", &k); for (j = 1; j <= k; j++) { b[j] = get(); } for (j = 1; j <= k; j++) { make(b[j], 1); //!!!找出每种情况 } for (j = 1; j <= n; j++) { int t = 0; for (x = 0; x < a[j].size(); x++) if (v[a[j][x]]) { t++; } if (t > mx[j]) { mx[j] = t, ans[j] = i;//!!!!找出每个group最适应的店 } } for (j = 1; j <= k; j++) { make(b[j], 0); //!!!相当于memset 把先前变为1的变回0 } } for (i = 1; i <= n; i++) { printf("%d\n", ans[i]); } }
XVII Open Cup named after E.V. Pankratiev. XXI Ural Championship
标签:class 压缩 const 进制 pen close space splay turn
原文地址:http://www.cnblogs.com/Aragaki/p/7617760.html