hdu 猜数字

这题的意思是找到最大的n使得m次之内的猜测可以猜到1~n之间的任何值。这里是二分思想的逆过程,1~h个数最多猜测log2(n+1)次(n为奇数),故

n=2^m-1;

#include"iostream"
#include"stdio.h"
#include"string.h"
#include"cmath"
using namespace std;
__int64 n;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n;
        __int64 result=pow(2,n)-1;
        //注意这里不能用cout输出,因为输出的会是科学计数法的形式
        printf("%I64d\n",result);
    }
    return 0;
}
View Code

 

posted @ 2015-03-10 12:37  Run_For_Love  阅读(212)  评论(0编辑  收藏  举报