n人比赛,可轮空,比赛轮数和场数

#include<stdio.h>
int chang(int x,int s){
        if(x==1)
        return s;
        else if(x==2)
        return s+1;
        else if(x%2!=0){
        s+=(x-1)/2;
                return chang((x+1)/2,s);
        }
        else{
        s+=x/2;
                return chang(x/2,s);
        }

}
int lun(int x){
        if(x==1)
        return 0;
        else if(x==2)
        return 1;
        else if(x%2!=0){
                return 1+lun((x+1)/2);
        }
        else
                return 1+lun(x/2);
}
int main()
{
    int K;
    scanf("%d", &K);
    while(K--)
    {
        int n;
        scanf("%d", &n);
        printf("%d %d
", lun(n),chang(n,0));
    }
    return 0;
    }
原文地址:https://www.cnblogs.com/tufujie/p/5345362.html