POJ 2443 位压缩加速
2013-09-27 15:14
246 查看
转化为01矩阵,将30行的每一列合并成一个int,对于某个询问进行与运算
#include <set> #include <map> #include <cmath> #include <queue> #include <stack> #include <string> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; typedef long long LL; const double PI = acos(-1.0); template <class T> inline T MAX(T a, T b){if (a > b) return a;return b;} template <class T> inline T MIN(T a, T b){if (a < b) return a;return b;} const int N = 111; const int M = 11111; const LL MOD = 1000000007LL; const int dir[4][2] = {1, 0, -1, 0, 0, -1, 0, 1}; const int INF = 0x3f3f3f3f; int g[40][10100]; int main() { int n; while (scanf("%d", &n) != EOF) { memset(g, 0, sizeof(g)); int p, cnt = 0, a, b, i, q, j, k; p = 1; for (i = 1; i <= n; ++i) { if (i % 30 == 0) {p = 1;cnt++;} scanf("%d", &k); for (j = 1; j <= k; ++j) { scanf("%d", &a); g[cnt][a] |= p; } p <<= 1; } scanf("%d", &q); for (i = 0; i < q; ++i) { scanf("%d%d", &a, &b); int f = 0; for (j = 0; j <= cnt; ++j) { if (g[j][a] & g[j][b]) break; } if (j != cnt + 1) { printf("Yes\n"); } else { printf("No\n"); } } } return 0; }
相关文章推荐
- 压位加速-poj-2443-Set Operation
- 压位加速-poj-2443-Set Operation
- POJ 2443 Set Operation(压位加速)
- POJ 2443:Set Operation 经典位运算好题
- POJ 2778 DNA Sequence && AC自动机 矩阵 矩阵加速
- poj 2443
- poj 2443 分类: poj 2015-04-13 19:35 36人阅读 评论(0) 收藏
- 使用hash表加速寻找-POJ 3349
- poj 2443
- [求和]poj 1990 MooFest #树状数组加速
- poj 2443 状态压缩 叉姐的魔法训练
- poj 3735 Training little cats 构造矩阵+稀疏矩阵加速连乘+矩阵快速幂
- POJ 3199 Uncle Jack(高精度加速乘)
- 位运算的艺术:POJ2443
- POJ 2443 位运算
- POJ 2443 Set Operation
- POJ 2778 DNA Sequence (AC自动机+矩阵加速,4级)
- POJ 3734 矩阵加速dp
- [POJ 2443] Set Operation (bitset)
- POJ2965解题报告(BFS,位压缩)