XVII Open Cup named after E.V. Pankratiev. XXI Ural Championship
Posted Aragaki
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了XVII Open Cup named after E.V. Pankratiev. XXI Ural Championship相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章
XVII Open Cup named after E.V. Pankratiev Grand Prix of Moscow Workshops, Sunday, April 23, 2017 Pro
XVII Open Cup named after E.V. Pankratiev Grand Prix of Moscow Workshops, Sunday, April 23, 2017 Pro
XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 P
XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 P
XVII Open Cup named after E.V. Pankratiev. Eastern Grand Prix. Problem G. Gmoogle 模拟字符串处理文本搜索
XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 P