ZJNU 1310 - 排队——中高级

蒟蒻做法:追踪1号队员,取他回到原来位置需要的次数

 1 /*
 2 Written By StelaYuri
 3 */
 4 #include<stdio.h>
 5 int main(){
 6     int T,t,n,ans,x;
 7     scanf("%d",&T);
 8     for(t=1;t<=T;t++){
 9         scanf("%d",&n);
10         ans=x=1;
11         while(x!=n+1){
12             if(x>n)
13                 x=(x-n)*2-1;
14             else
15                 x*=2;
16             ans++;
17         }
18         printf("Case #%d:\n%d\n",t,ans);
19     }
20     
21     return 0;
22 }

猜你喜欢

转载自www.cnblogs.com/stelayuri/p/12234861.html