【HDOJ】2721 Persistent Bits
题目有点长,但是题意说的很清楚。位操作。
1 #include <stdio.h> 2 3 int nums[65540]; 4 5 int main() { 6 int a, b, c, s; 7 int i, j, k, n, tmp, mask; 8 9 while (scanf("%d", &a)!=EOF && a) { 10 scanf("%d%d%d", &b, &c, &s); 11 n = mask = 0; 12 nums[n++] = tmp = s; 13 a = a%c; 14 b = b%c; 15 for (j=0; j<65537; ++j) { 16 tmp = (a*tmp + b) % c; 17 if (tmp == s) 18 break; 19 nums[n++] = tmp; 20 k = tmp ^ s; 21 mask |= k; 22 if (mask == 0xffff) 23 break; 24 } 25 j = 0x8000; 26 for (i=0; i<16; ++i) { 27 tmp = (j>>i); 28 k = tmp & s; 29 tmp &= mask; 30 if (tmp) 31 printf("?"); 32 else { 33 if (k) 34 printf("1"); 35 else 36 printf("0"); 37 } 38 } 39 printf("\n"); 40 } 41 42 return 0; 43 }