HDU 2178. Guess number "analytical ability exercises" "Reading ability Contact" "August 10"

Source: Internet
Author: User

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"

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.