ural 1136. Parliament】的更多相关文章

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1136 题目描述:给定一个按照(左子树-右子树-根)(即先序)遍历序列的树,求其按照 右子树-左子树-根 遍历的结果.(每个数都不同) 题目思路:按照题目意思其实构造的是一个二叉查找树,满足左子树元素都不大于当前根的元素,右子树元素都不小于当前根的元素. 而且二叉查找树按照 中序遍历 的结果是元素按照递增顺序输出(二叉查找树的性质).所以实际上又告诉了你中序遍历的结果(即把所给元素递增排序的结果…
二叉树水题,特别是昨天刚做完二叉树用中序后序建树,现在来做这个很快的. 跟昨天那题差不多,BST后序遍历的特型,找到最后那个数就是根,向前找,比它小的那块就是他的左儿子,比它大的那块就是右儿子,然后递归儿子继续建树. 代码: #include <cstdio> #include <cstdlib> const int maxn = 70000; struct Node { int v; Node *l; Node *r; }; int arr[maxn]; bool flag =…
题意 输入一棵树的后缀表达式(按左-右-中顺序访问),这棵树的每一个结点的数值都比它的左子树结点的数值大,而比它的右子树结点的数值小,要求输出其按右-左-中顺序访问的表达式.所有的数都为正整数,而且不会重复. 思路 很像根据中缀和后缀表达式求前缀表达式之类的题.方法自然也差不多.由DFS的括号性质可知,每一个树都对应表达式的一个区间,而此题中区间的最后一个就是树的根,然后根据根的大小可以把区间分为值小于和大于根值的两部分,即左子树和右子树,然后递归地输出右子树.左子树,最后再输出根即可. 代码…
Parliament Time limit: 1.0 secondMemory limit: 64 MB A new parliament is elected in the state of MMMM. Each member of the parliament gets his unique positive integer identification number during the parliament registration. The numbers were given in…
Parliament Time limit: 1.0 secondMemory limit: 64 MB A new parliament is elected in the state of MMMM. Each member of the parliament gets his unique positive integer identification number during the parliament registration. The numbers were given in…
1136 先由后左 再父 建一个二叉树 #include <iostream> #include<cstdio> #include<cstring> #include<stdlib.h> #include<algorithm> using namespace std; #define N 3010 int a[N]; int tr[N]; int g; void build(int s,int te,int ro) { if(s==te) { g…
1073. Square Country Time limit: 1.0 secondMemory limit: 64 MB There live square people in a square country. Everything in this country is square also. Thus, the Square Parliament has passed a law about a land. According to the law each citizen of th…
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串中心位置,RMQ询问LCP = min (height[rank[l]+1] to height[rank[r]]),注意的是RMQ传入参数最好是后缀的位置,因为它们在树上的顺序未知,且左边还要+1. #include <cstdio> #include <algorithm> #in…
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and each orders a juice cocktail. It could be from 1 to 3 different juices in each cocktail. There are three juices in the bar: apple, banana and pineappl…
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best programmer in the world! Now he regularly takes part in various programming contests, attentively listens to problems analysis and upsolves problems. But…