2013
12-12

# 九度-1151-位操作练习[解题代码]

1011 0000 0000 0001 经过循环左移一位后，变成 0110 0000 0000 0011, 若是循环左移2位，则变成 1100 0000 0000 0110

4
2 4
9 18
45057 49158
7 12

YES
YES
YES
NO

cpp 代码如下：
#include <stdio.h>
#include <math.h>
int main() {
int n;
int a, b;
int p = pow(2, 15);
while (scanf("%d", &n) != EOF) {
for (int i = 0; i < n; i++) {
scanf("%d %d", &a, &b);
int i;
for (i = 0; i < 16; i++) {
if (a >= p) {
a = ((a - p) << 1) + 1;
} else
a = a << 1;
if (a == b)
break;
}
if (i == 16)
printf("NO\n");
else
printf("YES\n");
}
}
return 0;
}

/**************************************************************
Problem: 1151
User: coder
Language: C
Result: Accepted
Time:10 ms
Memory:904 kb
****************************************************************/

java 代码如下：

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
while(s.hasNextInt()){
int n = s.nextInt();
for(int i=0; i<n; i++){
int a = s.nextInt();
int b = s.nextInt();
String str1 = Integer.toBinaryString(a);
String str2 = Integer.toBinaryString(b);
for(int j=0; j<16-str1.length(); j++)
str1 = "0" + str1;
for(int j=0; j<16-str2.length(); j++)
str2 = "0" + str2;
str1 = str1+str1;
if(str1.contains(str2))
System.out.println("YES");
else
System.out.println("NO");
}
}
}

}
/**************************************************************
Problem: 1151
User: coder
Language: Java
Result: Accepted
Time:160 ms
Memory:15988 kb
****************************************************************/

1. 凤逆天下：既然爱她，你还为何要娶别的女人，既然喜欢他，为何还让她哭得如此伤心欲绝，等你发现那是做错了，创伤还能恢复吗？