Bzoj1662: [usaco2006 Nov] round numbers

Source: Internet
Author: User
1662: [usaco Nov] Round numberstime limit: 5 sec memory limit: 64 MB
Submit: 147 solved: 84
[Submit] [Status] [discuss] Description as you know, cows don't have fingers so that they can't play the "Stone scissors cloth" to decide the order of who is milking first, for example. They cannot even use coins. So they passed the "round number" competition. The first ox selects an integer smaller than 2 billion. The second ox also selects an integer. If both numbers are "round numbers", the first ox wins. Otherwise, the second ox wins. If the number of 0 in the binary representation of a positive integer N is greater than or equal to 1, n is called "round number ". For example, for integer 9, the binary value is 1001,1001, which has two '0' and two '1'. Therefore, 9 is a round number. The binary value of 26 is 11010. Because it has 2 '0' and 3 '1', it is not a round number. It is obvious that the cows will spend a lot of energy converting into the system to determine who is the winner. Bessie wants to cheat, and thinks that as long as she can know the number of "round numbers" within a specified range. Help her write a program to tell her how many hround numbers are in a closed interval. The interval is [start, finish], which contains the two numbers. (1 <= start <finish <= 2,000,000,000) Input * Line 1: two integers separated by spaces, respectively, start and finish. Output * Line 1: Number of round numbers in the range of start .. Finish sample input2 12
Sample output
6

Output explanation:

2 10 1x0 + 1x1 round
3 11 0x0 + 2x1 not round
4 100 2x0 + 1x1 round
5 101 1x0 + 2x1 not round
6 110 1x0 + 2x1 not round
7 111 0x0 + 3X1 not round
8 1000 3x0 + 1x1 round
9 1001 2x0 + 2x1 round
10 1010 2x0 + 2x1 round
11 1011 1x0 + 3X1 not round
12 1100 2x0 + 2x1 round
Hint Source

Silver

Question: When someone else's question is not satisfied, write a copy by yourself... Obviously, the digital statistics are similar to the number topic of huashen. First, convert the problem to ans (R)-ans L-1), and then consider how to convert the to a binary sum (0)> sum (1) the number of assuming that the binary X is an array from the highest bit start enumeration for the bit of 1 assuming that the current enumeration to the I bit, then we will count the former I-1 bit and X are the same, however, if the I-bit is 0, the first such number must be <X. How can we calculate the number of 0> 1, note that the number of the current 0 is S0, and the number of 1 is S1. If there are still W freely selected BITs, the condition must be met, need S0 + S '0> = S1 + w-s '0, that is, s '0> = (s1-s0 + W)/2, then we only need C (W, (s1-s0 + W)/2) * 2 ^ (W-(s1-s0 + W)/2), meaning to select (s1-s0 + W)/2 position put 0, then the rest is casual. Of course, there are still many details to consider. For example, if the highest bit is obviously set to 0, it cannot be included in the final answer. Therefore, we need to determine the highest bit, that is, we need to count the number less than or equal to 10000000 ...... The number of satisfied questions can be converted to 10000000 ...... -1 = 11111111 ...... The answer to the statistics, plus 1, of course, the final 1 must be judged. The implementation of the code is estimated to have a lot of details, waiting for UPD... Code:

Bzoj1662: [usaco2006 Nov] round numbers

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.