[HDOJ5524] Subtree

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5524

Ask a complete binary tree How many seed trees contain different number of nodes.

First of all, it is possible that a complete binary tree may be full of two forks, and a subtree full of two forks is still full of two forks of trees. But the subtree of a complete binary tree has a tree that is full of two forks and the other is a complete binary tree. Depending on the number of nodes given, it is easy to know the shape of the left and right subtree and then solve it recursively. The number of n is too large for a long long.

1#include <algorithm>2#include <iostream>3#include <iomanip>4#include <cstring>5#include <climits>6#include <complex>7#include <fstream>8#include <cassert>9#include <cstdio>Ten#include <bitset> One#include <vector> A#include <deque> -#include <queue> -#include <stack> the#include <ctime> -#include <Set> -#include <map> -#include <cmath> +  - using namespacestd; +  AtypedefLong Longll; at ll N; - Set<ll>ans; -  - voidDFS (ll x) { -     if(x = =0|| Ans.count (x) >0) { -         return; in     } - Ans.insert (x); to     if(--x%2==0) { +DFS (X/2); -     } the     Else { *DFS (X/2); $DFS (X/2+1);Panax Notoginseng     } - } the  + intMain () { A     //freopen ("in", "R", stdin); the      while(~SCANF ("%i64d", &N)) { + ans.clear (); - DFS (n); $printf"%d\n", Ans.size ()); $     } -     return 0; -}

[HDOJ5524] Subtree

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.