UVa 679-dropping Balls

Source: Internet
Author: User

Title: There is a complete two-fork tree, each node is a switch, initially completely closed, the ball is discarded from the vertex.

Each time the switch ball is reversed. Now ask the K ball to drop to D when the layer switch is number.

Analysis: Binary encoding. After several simulations, the ball will let the switch form a continuous binary number representation (the root is low).

When you put the K ball. The switch state is exactly the binary K. Using the remainder of modulo 2 to infer the direction is possible.

Explanation: The observation law simulates the processing to be possible.

#include <iostream> #include <cstdlib> #include <cstring> #include <cstdio>using namespace std; int main () {int n,r,l;while (CIN >> n && n >= 0) {while (n--) {cin >> l >> r;int k = 1;while (--L) {if (r%2) k = K<<1;else k = (k<<1) +1;r = (r+1) >>1;} cout << k << Endl;}} return 0;}

Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

UVa 679-dropping Balls

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.