(Hdu step 4.1.8) number (calculate the maximum number that can be guessed n times), hdu4.1.8

Source: Internet
Author: User

(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 Input
213
 
Sample Output
17
 
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 ;}





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.