UVaLive/LA 6809 Spokes Wheel(搜索,二进制循环移位)
2014-11-23 21:45
453 查看
// Author: Yuan Zhu #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #define ll long long using namespace std; int t; char a[40], b[40]; int toint(char c) { if(c >= '0' && c <= '9') return c - '0'; else return c - 'A' + 10; } int main() { scanf("%d", &t); for (int ca = 1; ca <= t; ca++) { scanf("%s%s", a, b); ll A = 0, B = 0, rA = 0, rB = 0; for (int i = 0; a[i]; i++) A = A * 16 + toint(a[i]); for (int i = 0; b[i]; i++) B = B * 16 + toint(b[i]); ll AA = A, BB = B; int cA = 0, cB = 0; while (AA) cA++, AA /= 2; while (BB) cB++, BB /= 2; ll tmpA = A; int l = -1, r = -1; for (int i = 1; i < 32; i++) { ll c = tmpA & 1; tmpA >>= 1; if (c) tmpA += (1LL << 31); if (tmpA == B) { r = i; break; } } tmpA = A; for (int i = 1; i < 32; i++) { ll c = tmpA & (1LL << 31); tmpA <<= 1; if (c) tmpA -= (1LL << 32), tmpA++; if (tmpA == B) { l = i; break; } } printf("Case #%d: ", ca); if (A == B) printf("0 Any\n"); else if (l == -1 && r == -1) printf("Not possible\n"); else if (l == r) printf("%d Any\n", l); else if (r < l) printf("%d Right\n", r); else printf("%d Left\n", l); } return 0; }
相关文章推荐
- UVALive - 6809 Spokes Wheel(位运算)
- UVaLive 6809 Spokes Wheel (模拟)
- UVALive 3907 (LA 3907) Puzzle AC自动机 + 搜索DP 记录路径
- UVALive 3942 (LA 3492) Remember the Word Trie树 + 记忆化搜索
- UVaLive ( LA ) 3516 - Exploring Pyramids (DP 递推)
- Regionals 2009 :: Asia - Hsinchu UVALIVE, 4527 Vaccination Centers - 搜索剪枝
- UVALive 5844 dfs暴力搜索
- UVALive 6255 Kingdoms --状态搜索
- UVALive 5963 (LA 5963) Confusion in the Problem Set 二分图匹配 (或 YY)
- uvalive5992(搜索)
- UVALIVE 5893 计算几何+搜索
- 【UVALive 7364】Robots(逆向思维+搜索)
- UVALive-4793 Robots on Ice 搜索加剪枝
- 搜索(DFS+BFS)——UVA Live 6455
- Regionals 2009 >> Asia - Hsinchu UVALIVE, 4528 Schedule Pairs of Jobs - 搜索回溯
- UVALive 3621 Power Calculus n次幂最少需要几次乘除得到 搜索
- UVaLive/LA 6800 The Mountain of Gold?(BellmanFord判负环+记忆化搜索)
- UVALive 6669 (LA 6669) Dragon’s Cruller (康托展开 + 最短路)
- UVALIVE 5893 计算几何+搜索
- UVALive 6902 Three Squares(二分 + 搜索)