猜数字
A有1数m,B来猜.B每猜一次,A就说太大t太小或;对了问B猜n次可以猜到的最大数。
Input
第1行是整数T,表示有T组数据,下面有T行 <br>每行一个整数n (1 ≤ n ≤ 30) <br>
Output
猜n次可以猜到的最大数<br>
Sample Input
2<br>1<br>3
Sample Output
1<br>7<br>
Author
Zhousc
Source
ECJTU 2008 Summer Contest
题意:中文题
思路:看了网上的思路,在1到h间的每一个数,你都能在m次内把它猜出来,
所以说在最坏的情况下,在1到h间,你最多只要猜log2(h)+1(取整)次,所以易知==>h=2^m-1.即猜m次,能猜到的最大的数为2^m-1。
感想:这个题挺绕的,举个例子比较好理解,代码就超级简单了
AC代码:
#include <cstdio>
#include<iostream>
#include<stdio.h>
#include<numeric>
#include<math.h>
using namespace std;
int main()
{
int T,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
n=pow(2,n)-1;
cout<<n<<endl;
}
}