码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 猜数字

时间:2015-03-10 13:38:08      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

这题的意思是找到最大的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

 

hdu 猜数字

标签:

原文地址:http://www.cnblogs.com/acm-jing/p/4325651.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!