题目链接
https://icpcarchive.ecs.baylor.edu/external/68/6809.pdf
枚举可以过,但弄个字符串或者数组去处理进制转换的确很麻烦,在vj里找到个大神的代码,真tm神奇,在这里贴下。
#include<iostream> #include<cstring> #include<string> #include<cstdio> using namespace std; int main() { unsigned int A, B; unsigned int a, b; int casen; cin >> casen; for (int cas = 1; cas <= casen;cas++) { scanf("%x%x", &A, &B); int r=0, l=0; a = A, b = B; while (a != b&&l<32){ a = (a >> 31) | (a << 1); l++; } a = A, b = B; while (a != b&&r<32){ a = (a << 31) | (a >> 1); r++; } if (l == 32) printf("Case #%d: Not possible\n", cas); else if (l == r) printf("Case #%d: %d Any\n", cas, l); else if (l<r) printf("Case #%d: %d Left\n", cas, l); else printf("Case #%d: %d Right\n", cas, r); } }
时间: 2024-10-05 11:53:01