Wenbao and two fork tree

Source: Internet
Author: User

Two-fork Tree

The left and right nodes of node K are 2k and 2k+1 respectively.

Ball Drop

Place the ball on the first node and fall, each point has a switch (the ball falls at that point when the state will change), when the point is closed to the left, or to the right, the first ball fell on the node

Simulate directly according to test instructions

1#include <cstdio>2#include <cstring>3 using namespacestd;4 Const intMAXN = -;5 ints[1<<MAXN];6 intMain () {7     intd,i;8      while(SCANF ("%d%d", &d, &i) = =2){9memset (s),0,sizeof(s));Ten         intK, n = (1&LT;&LT;D)-1; One          for(inti =0; i < I; i++){ AK =1; -              for(; ; ) { -S[K] =!S[k]; thek = S[k]? k*2: k*2+1; -                 if(k > N) Break; -             } -         } +printf"%d\n", k/2); -     } +     return 0; A}

If you continue to observe, you will find the law, each odd and even different ball falls around the same

Just know that the ball is the first few fall on the node can know the closure of the point switch, that is, the ball of the left and right

This can save a lot of time and unnecessary arrays

1#include <cstdio>2#include <cstring>3 using namespacestd;4 intMain () {5     intd,i;6      while(SCANF ("%d%d", &d, &i) = =2){7         intK =1;8          for(inti =0; I < D1; i++){9             if(i&1){TenK = k*2; I = (i+1)/2; One             } A             Else{ -K = k*2+1; I/=2; -             } the         } -printf"%d\n", k); -     } -     return 0; +}

Wenbao and two fork tree

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.