poj-2965-The Pilots Brothers' refrigerator(巧妙的位运算)
2016-03-28 08:18
489 查看
传送门
这道题和poj1753 类似,都巧妙的运用了位运算
这道题和poj1753 类似,都巧妙的运用了位运算
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <vector> #include <set> #include <string> #define N 1000010 #define ll long long using namespace std; int cs[] = {0x111f, 0x222f, 0x444f, 0x888f, 0x11f1, 0x22f2, 0x44f4, 0x88f8, 0x1f11, 0x2f22, 0x4f44, 0x8f88, 0xf111, 0xf222, 0xf444, 0xf888}; int po[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768}; int aa[2][20]; int main(){ #ifndef ONLINE_JUDGE freopen("1.txt", "r", stdin); #endif int v1, v2, i, j, ans, tmp, t, at; char c; v1 = 0; for (i = 0; i < 16; i++){ cin >> c; if (c == '+'){ v1 ^= po[i]; } } ans = 999999; t = 0; for (i = 0; i < 65536; i++){ v2 = v1; tmp = 0; for (j = 0;j < 16; j++){ if (i&po[j]){ tmp++; v2 ^= cs[j]; aa[t][tmp] = j; } } if (v2 == 0){ if (ans >= tmp){ ans = tmp; at = t; if (t == 0){ t = 1; }else{ t = 0; } } } } cout << ans << endl; for (i = 1; i <= ans; i++){ cout << aa[at][i]/4+1 << ' ' << aa[at][i]%4+1 << endl; } return 0; }
相关文章推荐
- MiseringThread.java 解析页面线程
- MiseringThread.java 解析页面线程
- 移动HTML5前端性能优化指南
- [ZZ]计算机视觉、模式识别、机器学习常用牛人主页链接
- ubuntu更新后出现grub-efi-amd64 not configure yet错误
- 0327
- 有没有一段代码,让你觉得人类的智慧也可以璀璨无比?
- 【项目管理和构建】——Maven下载、安装和配置
- POJ 3463 Sightseeing
- SQL Server安全(6/11):执行上下文与代码签名(Execution Context and Code Signing)
- 完整模式下SQL日志收缩
- CodeForces 25C(Floyed 最短路)
- CodeForces 25C(Floyed 最短路)
- CodeForces Roads not only in Berland(并查集)
- CodeForces Roads not only in Berland(并查集)
- 项目中关于IE7的兼容问题
- Module Thinking之networks
- read excel files with python and xlrd
- CodeForeces 25E (kmp)
- extract things from excel files.