ZOJ 3805 Machine

Source: Internet
Author: User

Topic Link ~~>

To do the idea : the game thought of the method, but did not have AC, unfortunately, did not take into account the right side of the sub-tree of equal situation, the result of the cup has, after the game to smooth a bit of ideas on AC, the game is not calm, the mind is not clear, the future to pay attention.

Problem Solving Ideas:

The topic is a tree, just to put the right node more on the left son on the good, so reduce the number, recursion, pay attention to the two sons of the same situation need to add 1.

Code:

#include <iostream> #include <sstream> #include <map> #include <cmath> #include <fstream> #include <queue> #include <vector> #include <sstream> #include <cstring> #include <cstdio > #include <stack> #include <bitset> #include <ctime> #include <string> #include <cctype  > #include <iomanip> #include <algorithm>using namespace std, #define INT __int64#define L (x) (x * 2) #define  R (x) (x * 2 + 1) const int INF = 0X3F3F3F3F; Const double ESP = 0.0000000001; const double PI = ACOs ( -1.0); const INT MOD = 1000000007; const int MY = (1<<5) + 5; const int MX = 100000 + 5; int n; struct node{int le, RT;}    T[MX]; int dfs (int u)//Transform left and right sub-tree, calculate there are several sons {int lson = 0, Rson = 0, num = 0;    if (t[u].le)//calculate left subtree Lson = DFS (t[u].le);    if (T[U].RT)//Calculate right subtree Rson = DFS (T[U].RT);    if (Lson < Rson)//If Zuozi right son of small less right operand subtree of the right son swap (t[u].le, t[u].rt); if (Lson = = Rson) return Lson + 1; Note Return Max (Lson, Rson);}    int main () {//freopen ("Input.txt", "R", stdin);    int x;        while (~SCANF ("%d", &n)) {memset (t, 0, sizeof (t));            for (int i = 2; I <= n; ++i) {scanf ("%d", &x);            if (t[x].le) t[x].rt = i;        else T[x].le = i;    } printf ("%d\n", DFS (1)); } return 0;}


ZOJ 3805 Machine

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.