UVaLive/LA 6809 Spokes Wheel(搜索,二进制循环移位)
来源:互联网 发布:c语言开发实战 pdf 编辑:程序博客网 时间:2024/05/16 08:54
// Author: Yuan Zhu#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#define ll long longusing 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;}
0 0
- UVaLive/LA 6809 Spokes Wheel(搜索,二进制循环移位)
- UVALive - 6809 Spokes Wheel(位运算)
- SPOKES WHEEL
- 二进制循环移位问题
- UVaLive/LA 6800 The Mountain of Gold?(BellmanFord判负环+记忆化搜索)
- UVaLive/LA 6800 The Mountain of Gold?(BellmanFord判负环+记忆化搜索)
- UVaLive/LA 6801 Sequence(DP)
- UVaLive/LA 6802 Turtle Graphics(水题)
- UVaLive/LA 6805 Pantun Grader(模拟)
- LA 4329/uvalive 4329 (树状数组)
- UVaLive(LA) 3902 Network,Seoul 2007
- 循环移位(转)
- 循环移位(翻转算法)
- UVALive(LA) 3644 X-Plosives (并查集)
- UVaLive LA 4356 - Fire-Control System (扫描法 思维)
- UVaLive LA 4256 | UVa 1424 - Salesmen(简单DP)
- UVaLive ( LA ) 3516 - Exploring Pyramids (DP 递推)
- UVaLive/LA 6804 Group of Strangers(图论)
- Android PendingIntent
- pat,1031Hello World for U
- linux RTNETLINK answers: File exists错误解决方法
- C++标准库---STL三大序列容器vector&deque&list
- 产品原型工具
- UVaLive/LA 6809 Spokes Wheel(搜索,二进制循环移位)
- Java基础回顾(5)
- Android智能机器人“小慕”的实现
- 详解之android动画interpolator插补器
- 黑马程序员_JAVA_网络编程
- ubuntu12.04克隆后没有cannot find device eth0
- 黑马程序员——java基础——多线程
- Morphological Antialiasing
- undefined reference to `__android_log_print'解决