hdu 1393

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1393

题意:一个钟面只有一根分针。对于一个数字d,把中面上的分针指向的时间s往后拨s的d倍。问给定d,重复这样的操作多少次能回拨到0。若不能则输出Impossible。

mark:因为钟面只有60分钟,所以最多不会超过60次,直接暴力就可。

代码:

# include <stdio.h>


int main ()
{
int i, s, d, cnt ;
int tab[100] ;
while (~scanf ("%d%d", &s, &d) && (s||d))
{
for (i = 0 ;i < 60 ; i++) tab[i] = 0 ;
cnt = 0 ;
while (s != 0 && tab[s] == 0)
{
tab[s] = 1 ;
s = (s*(d+1))%60 ;
cnt ++ ;
}
if (s != 0) puts ("Impossible") ;
else printf ("%d\n", cnt) ;
}
return 0 ;
}



原文地址:https://www.cnblogs.com/lzsz1212/p/2353093.html