HDU 2178 guess number

Source: Internet
Author: User

To guess the maximum number M, that is to say, you can guess every number between 1 and M in n times! Http://hi.baidu.com/xiao%5Fyu%5Ffeng/blog/item/11ab800ed1a7a3236159f334.html

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 within n times between 1 and 2 ^ n-1. If it is greater than this number, we may not be able to guess it within n times. For example, we have to guess at least three times between 1 and 7.

# Include <stdio. h> int main () {int t, n, m; scanf ("% d", & T); While (t --) {scanf ("% d ", & N); M = 1; while (n --) m <= 1; printf ("% d \ n" m-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.