Balls regularity of UVA-679 dropping

Source: Internet
Author: User

The main topic: Give a completely binary tree, each node has a switch, just start the switch is open, the ball passes through the node after the switch is closed (except the root node). If the ball passes through the node's sibling node, then the switch on the node opens again.
Now put the ball to the root node, preference to the left node to go, if the left node switch off, select the right. After the ball falls to the leaf node, the other ball continues, asking the nth ball to which leaf node it falls.

Problem-solving ideas: In fact, this problem is quite water, because it is two fork tree, so can be determined by the ball's odd and even line to determine which branch to go, if n 2 = = 0 is the nth to the right to go, and vice versa is to go to the left, and so on to launch the last ball fell where

#include <cstdio>#include <cstring>using namespace STD;intMain () {intD, L;scanf("%d", &d); while(scanf("%d", &d) = =1&& D! =-1) {scanf("%d", &l);intCur =1, ans =1; while(Cur < (1<< D) {ans = cur; Cur *=2;ifL2==0) cur++; L = (L +1) /2; }printf("%d\n", ans); }return 0;}

Balls regularity of UVA-679 dropping

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.