hdu 2178 猜数字

题目:

Problem Description
A有1数m,B来猜.B每猜一次,A就说"太大","太小"或"对了" 。 
问B猜n次可以猜到的最大数。 
 
Input
第1行是整数T,表示有T组数据,下面有T行 
每行一个整数n (1 ≤ n ≤ 30) 
 
Output
猜n次可以猜到的最大数
 
Sample Input
2
1
3
 
Sample Output
1
7
 
 
在1到m间,你最多只要猜log2(m)+1(取整)次,所以易知==>m=2^n-1.即猜n次,你能猜到的最大的数为2^n-1
 
 
代码:
 1 #include<iostream>
 2 
 3 using namespace std;
 4 
 5 int main( ) {
 6 
 7     int N,n;
 8     cin >>N;
 9     while(N--){
10         cin >>n;
11         cout << (2<<(n-1))-1 <<endl;
12     }
13     return 0;
14 }
View Code
 
原文地址:https://www.cnblogs.com/lysr--tlp/p/ppp.html