(Hdu step 4.1.8) number (calculate the maximum number that can be guessed n times), hdu4.1.8
Question:
Guess number |
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
Total Submission (s): 318 Accepted Submission (s): 247 |
|
Problem DescriptionA has 1 m, B to guess. B each time, A said "too big", "Too small" or "right ". Ask B the maximum number that can be guessed n times. |
The Input row 1st is an integer T, indicating that there are T groups of data, and there are T rows below Each row has an integer n (1 ≤ n ≤ 30) |
Maximum number of Output guesses that can be guessed n times |
Sample Input213 |
Sample Output17 |
AuthorZhousc |
Sourceecjtu2008 Summer Contest |
Recommendlcy |
Question Analysis:
To guess the maximum number m, that is to say, you can guess every number between 1 and m in n times!
Therefore, in the worst case, you only need to guess log2 (m + 1) (integer) at most between 1 and m, so Yi Zhi => m = 2 ^ n-1. that is, you can guess n times. The maximum number you can guess is 2 ^ n-1. we can also think that we can guess from the numbers 1 to 2 ^ n-1 over n times. If it is greater than this number, we may not be able to guess it for n times. For example, we have to guess at least three times between 1 and 7.
The Code is as follows:
/** I. cpp ** Created on: February 16, 2015 * Author: Administrator */# include <iostream> # include <cstdio> # include <cmath> using namespace std; int main () {int t; scanf ("% d", & t); while (t --) {int n; scanf ("% d", & n); printf ("% d \ n ", (int) pow (2 + 0.0, n)-1);} return 0 ;}