The problem of NYOJ-744 ants (i.)

Source: Internet
Author: User

This question is said to be water problem, is not done out, see a lot of problems, feel this law did not understand, later in the discussion area saw a question, feel a little understand, write your own understanding

First of all, to understand the meaning of different or simple sentence: the same as 0 different 1, since this, let the interval a, a, or the largest one, then the largest group is how much, thanks to a few sets of data, first to find out the value of a ^ B, because this is the most basic, so x=a^b, then x binary first 1 should appear in B 1, And a is 0, because B > A, this can be a hands-on experiment, then because the arbitrary two number is located between A and B, so, this arbitrary two number of bits number must be less than or equal to x bits number, because he is an interval, So you can certainly find that the first 1 of the X's binary is all 1, then this maximum value, this time also becomes the x bits number is all 1, so n = x bits number, the result is 2^n-1, for example, 5 and 7, then 5 binary 101, 7 binary 111, 5^7=010, the first 1 appears in the second position, then 1 to the right of the 0 must be able to change the value of two numbers, that is, the maximum to 5, 6, so the XOR is 3, the binary is 11, so that is 2^2-1 = 3;

The code is as follows:

1  2#include <cstdio>3 4 using namespacestd;5 6 intMain ()7 {8     9     Long LongA, B;Ten      while(~SCANF ("%lld%lld", &a, &b)) One     { A      -         Long Longx = a ^b; -         intc =0; the          while(x) -         { -C++; -X >>=1; +         } -         Long Longres =1; +          for(inti =0; I < C; i++) A         { atRes *=2; -         } -printf"%lld\n", RES-1); -     } -     return 0; -}

The problem of NYOJ-744 ants (i.)

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.