UVa712 s-trees (binary tree)

Source: Internet
Author: User

Links: http://acm.hust.edu.cn/vjudge/problem/19200
Analysis: What does the XI have to do with this question? Binary tree just corresponds to binary, the root node is expressed as 0, the left subtree is i*2+0, the right subtree is i*2+1, all leaf nodes can be used 0~ (1<<n)-1 (n is the number of layers, the root node is the No. 0 layer) of the number.

1#include <cstdio>2 3 intMain () {4     intN, Kase =0;5      while(SCANF ("%d", &n) = =1&&N) {6         intx[Ten];Charbuf[ $];7          for(inti =0; I < n; i++) scanf ("%s", buf);8         intm =1<< N;intleaf[ $];9scanf"%s", buf);Ten          for(inti =0; I < m; i++) OneLeaf[i] = buf[i]-'0'; Aprintf"S-tree #%d:\n", ++Kase); -         intQ scanf"%d", &q); -         intdir[Ten]; the          for(inti =0; i < Q; i++) { -scanf"%s", buf); -             intv =0; -              for(intj =0; J < N; J + +) +v = v *2+ Buf[j]-'0'; -printf"%d", Leaf[v]); +         } Aprintf"\ n"); at     } -     return 0; -}

UVa712 s-trees (binary 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.