Guess numbers
Problem Descriptiona has 1 numbers m,b to guess. b Every time you guess, a says "too big", "too small" or "right."
Ask B to guess the maximum number of n times you can guess.
Input line 1th is an integer t, which indicates that there is a T-group of data, the following T-line
One integer per line n (1≤n≤30)
Output guess n times the maximum number that can be guessed
Sample Input
213
Sample Output
17
Oh, my God, what's the meaning of this question? -----First FeelingUnderstand
carefully: for example, 3 times in the data can guess the maximum 7, that is, the number within 7 can be guessed within 3 times. This is the meaning of the question. Then analyze: in the worst case, in the 1 to M, you can only guess log2 (m) +1 (rounding) times (two points), so easy to know m=2^n-1. Guess n times, the number of the largest number you could guess is 2^n-1. We may also think that between 1 and 2^n-1, We can all guess it in n times. This is where the code can go:
#include <cstdio> #include <cmath>int main () { int n,t; while (scanf ("%d", &t)!=eof) {while (t--) { scanf ("%d", &n); printf ("%d\n", (int) POW (2,n)-1); } } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 2178. Guess number "analytical ability exercises" "Reading ability Contact" "August 10"