猜数字
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3239 Accepted Submission(s): 2341
Problem Description
A有1数m,B来猜.B每猜一次,A就说"太大","太小"或"对了" 。
问B猜n次可以猜到的最大数。
问B猜n次可以猜到的最大数。
Input
第1行是整数T,表示有T组数据,下面有T行
每行一个整数n (1 ≤ n ≤ 30)
每行一个整数n (1 ≤ n ≤ 30)
Output
猜n次可以猜到的最大数
Sample Input
2 1 3
Sample Output
1 7
/*
hdoj 2178 题目意思还真不好懂
在最坏的情况下,在1到m间,你最多只要猜n=log2(m)+1(取整)次,
m=2^n-1.即猜n次,你能猜到的最大数的数为2^n-1.
在数1到2^n-1间,我们都可以在n次内猜出来。
比如 7 我们都可以在3次内猜出来
先猜 4 小=>6 小=> 7
4 小=>6 大=> 5 这里已经3步内搞定 4 5 6 7
同理
4 大=>2 小=> 3
4 大=>2 大=> 1 这里已经3步内搞定 1 2 3 4
所以说3步之内能猜7以内
直接pow(2,n) DEV c 可以 但是 OJ编译出错
double pow(double, double)
/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:361: note: long double std::pow(long double, int)
/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:357: note: float std::pow(float, int)
/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:353: note: double std::pow(double, int)
/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:349: note: long double std::pow(long double, long double)
/bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/cmath:345: note: float std::pow(float, float)
可以改为c 也可以强制下类型
*/
//#include<iostream>
#include<stdio.h>
#include<math.h>
//using namespace std;
int main()
{
int t,n,k;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
k=int(pow(2,n)-1);
printf("%d\n",k);
}
return 0;
}