地址:http://acm.hdu.edu.cn/showproblem.php?pid=2721
题意:给出a、b、c、s。s是初值,每次变化有s = (a*s+b)%c。如此直到重复。这些数都写成16比特的,如果某位在所有数都是0则输出0,是1则输出1,如果都有可能输出问号。直接暴搞就可以。。。
代码:
1 # include <stdio.h> 2 # include <string.h> 3 4 5 int vis[70000] ; 6 7 8 int main () 9 { 10 int a, b, c, s, i, bit ; 11 char ch[20] ; 12 13 while (~scanf ("%d", &a) && a) 14 { 15 scanf ("%d%d%d", &b, &c, &s) ; 16 memset (vis, 0, sizeof(vis)) ; 17 for (i = 0 ; i < 16 ; i++) 18 ch[i] = ((s>>(15-i)) & 1) + '0' ; 19 while (!vis[s]) 20 { 21 vis[s] = 1 ; 22 for (i = 0 ; i < 16 ; i++) 23 { 24 bit = ((s>>(15-i)) & 1) ; 25 if (ch[i]-'0' != bit) ch[i] = '?' ; 26 } 27 s = (((a*s)%c) + (b%c))%c ; 28 } 29 for (i = 0 ; i < 16 ; i++) 30 printf ("%c", ch[i]) ; 31 printf (" ") ; 32 } 33 return 0 ; 34 }