HDU 1008 猜数字

来源:互联网 发布:美工兼职 编辑:程序博客网 时间:2024/05/22 15:21
Problem Description
A有1数m,B来猜.B每猜一次,A就说&quot;太大&quot;,&quot;太小&quot;或&quot;对了&quot; 。 <br>问B猜n次可以猜到的最大数。 <br>
 

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>
简单题意:猜数字,猜固定次数能猜到的最大值
解题思路:设有一个猜n次必定能猜到m,二分思想,(((m+1)/2+m+1)+m+1)=m,……
AC代码:
#include<iostream>
#include<cmath> 
using namespace std;
int main()
{
int n ,t ;
cin >> n;
while(n --){
cin >> t; 
int k ;
k = pow(2,t) - 1 ;
cout << k << endl ;
}
return 0; 
}
0 0