[恢]hdu 1210

2011-12-16 00:57:22

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

题意:中文。。。

mark:枚举了”1“的变化位置,然后计数。当1回到第一位,则停止。

代码:

# include <stdio.h>


int calc(int n)
{
int cnt = 0, cur = 1 ;
do{
if (cur <= n) cur = 2*cur ;
else cur = (cur-n) * 2 - 1 ;
cnt++ ;
}while (cur != 1) ;
return cnt ;
}


int main ()
{
int n ;
while (~scanf ("%d", &n))
printf ("%d\n", calc(n)) ;
return 0 ;
}



posted @ 2012-01-06 16:32  Seraph2012  阅读(180)  评论(0编辑  收藏  举报