UVA 10940 Throwing cards away II

题意:写了几个发现规律f(n)=f(2^m+k)=2*k,注意f(1) = 1,为此W了一次
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main(){
    int n;
    while (scanf("%d",&n) != EOF && n){
        if (n == 1){
            printf("1\n");
            continue;
        }
        int cnt = 1;
        while (cnt < n)
            cnt <<= 1;
        int ans = (n-cnt/2)*2;
        printf("%d\n",ans);
    }
    return 0;
}



你可能感兴趣的:(UVA 10940 Throwing cards away II)