HDU 1014 Uniform Generator
好久没有刷题了。。。今天一来就碰到个不好解决的,不,应该是自己实力太弱了……
此题光是理解题意就用了不少时间,理解了以后对于如何判断1到MOD-1的数字全出现又让我恼火了一阵子。。。
1 #include <stdio.h> 2 #include <math.h> 3 4 int main(){ 5 int s, m, i; 6 while(scanf("%d%d",&s,&m) != EOF){ 7 int a[100001] = {0}; 8 int seed = 0; 9 while(!a[seed]){ 10 a[seed] = 1; 11 seed = (seed + s) % m; 12 } 13 for(i = 0; i < m; i++){ 14 if(a[i] == 0){ 15 printf("%10d%10d Bad Choice\n\n",s,m); 16 break; 17 } 18 } 19 if(i == m){ 20 printf("%10d%10d Good Choice\n\n",s,m); 21 } 22 } 23 return 0; 24 }
Everything will be ok in the end. If it is not ok then it is not the end.