AtCoder - 2061 Tree Restoring】的更多相关文章

Problem Statement Aoki loves numerical sequences and trees. One day, Takahashi gave him an integer sequence of length N, a1,a2,…,aN, which made him want to construct a tree. Aoki wants to construct a tree with N vertices numbered 1 through N, such th…
Tree Restoring Time limit : 2sec / Memory limit : 256MB Score : 700 points Problem Statement Aoki loves numerical sequences and trees. One day, Takahashi gave him an integer sequence of length N, a1,a2,…,aN, which made him want to construct a tree. A…
Binary Tree Restoring 思路: 递归 比较a序列和b序列中表示同一个子树的一段区间,不断递归 代码: #include<bits/stdc++.h> using namespace std; #define LL long long #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) ; int a[N],b[N],par[N],posa[N],posb[N],sum[N],n; void dfs(int…
Binary Tree Restoring Time Limit: 1 Second      Memory Limit: 65536 KB      Special Judge Given two depth-first-search (DFS) sequences of a binary tree, can you find a binary tree which satisfies both of the DFS sequences? Recall that a binary tree i…
题目传送门:https://agc005.contest.atcoder.jp/tasks/agc005_c 题目大意: 给定一个长度为\(N\)的整数序列\(A_i\),问能否构造一个\(N\)个节点的树,满足树上到第\(i\)个点的距离为\(A_i\),问能否构造 我真要吐槽一下--\(N\leqslant 100\),2s时限,256MB内存--我一直以为是个\(O(n^3\log n)\)级别的题,然后--\(O(n)\)?烟雾弹??? 唉,其实还是因为自己太菜了-- 首先知道一些性质(…
地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3965 题目: iven two depth-first-search (DFS) sequences of a binary tree, can you find a binary tree which satisfies both of the DFS sequences? Recall that a binary tree is a tree in which…
题目链接 https://atcoder.jp/contests/agc030/tasks/agc030_b 题解 细节好题.. 首先假设第一步往右走,那么可以发现当拐弯的次数一定时路径是唯一的 于是可以枚举这个值 然后很烦的是枚举之后要分奇偶讨论.. 最后再翻过来做一遍处理第一步往左走就行了 时间复杂度\(O(n)\) 代码 #include<cstdio> #include<cstdlib> #include<iostream> #include<algori…
Description ​ 给出一个数组a,要求构造一颗树,使节点x距离最远的点的距离为\(a_x\). Input ​ 第一行一个正整数NN(2≤N≤1002≤N≤100) ​ 接下来一行,有NN个正整数,描述序列a1,a2,...,aNa1,a2,...,aN(1≤ai≤N−11≤ai≤N−1) Output ​ 如果对于输入的序列存在这样的树,则输出"Possible",否则输出"Impossible".二者皆不含引号. Sample Input #Sampl…
ZOJ3965 给定一颗二叉树的两种DFS序列 输出一种可能的二叉树的结构. 考察树的递归性质,不要想的太复杂. 当前节点在两个串中后面的节点假如不同则能确认两个子树,如果相同则把下个点作当前点的一个儿子.如果子树中还有未连根的点则接到当前点下.son数组表示每个点的子树有多少个点.pos数组记录每个数在每个序列中的位置.dfs中p1,p2指向同一个数 lim1,lim2表示当前点子树可能最大的子树范围. #include<iostream> #include<cstdio> #i…
AtCoder Grand Contest 005 A - STring 翻译 给定一个只包含\(ST\)的字符串,如果出现了连续的\(ST\),就把他删去,然后所有位置前移.问最后剩下的串长. 题解 模拟栈,和维护括号一样的. #include<iostream> #include<cstring> using namespace std; #define MAX 200200 char ch[MAX]; int ans,tot; int main() { cin>>…