POJ3718

来源:互联网 发布:淘宝仓库发货员 编辑:程序博客网 时间:2024/06/18 16:49
描述
给出两个不大于65535的非负整数,判断其中一个的16位二进制表示形式,是否能由另一个的16位二进制表示形式经过循环左移若干位而得到。


循环左移和普通左移的区别在于:最左边的那一位经过循环左移一位后就会被移到最右边去。比如:
1011 0000 0000 0001 经过循环左移一位后,变成 0110 0000 0000 0011, 若是循环左移2位,则变成 1100 0000 0000 0110
输入
第一行是个整数n, 0 < n < 300000,表示后面还有n行数据
后面是n行,每行有两个不大于65535的非负整数
输出
对于每一行的两个整数,输出一行,内容为YES或NO
样例输入
4
2 4
9 18
45057 49158
7 12
样例输出
YES
YES
YES
NO
来源

Guo Wei


这道题简直毒到爆炸,有很多隐形的限制,甚至似乎后台编译器也有bug:

代码一:

#include<stdio.h>#define SL sizeof(unsigned short)*8int main() {int n;scanf("%d", &n);//while(~scanf("%d", &n))while (n--) {bool success = false;unsigned short b,k;scanf("%hu%hu",&b,&k);for (int i = 0; i < SL; i++) {unsigned short t = ((k << i) | (k >> (SL - i)));if (t == b) {success = true;break;}}if (success) {printf("YES\n");}else {printf("NO\n");}}return 0;}

代码二:

#include<stdio.h>#define SL sizeof(unsigned short)*8int main() {int n;scanf("%d", &n);//while(~scanf("%d", &n))while (n--) {bool success = false;unsigned short b=0,k=0;scanf("%hu%hu",&b,&k);for (int i = 0; i < SL; i++) {unsigned short t = ((k << i) | (k >> (SL - i)));if (t == b) {success = true;break;}}if (success) {printf("YES\n");}else {printf("NO\n");}}return 0;}


两段代码,只有 unsigned short b,k;这句有没有初始化得到的结果完全不同,代码一AC了而代码二WA,简直有毒吧!!!


我有一句MMP我不仅要说我还要while(1)