[题解]CF611H New Year and Forgotten Tree 神题了... 题目描述 给定你一棵树,可是每个节点上的编号看不清了,只能辨别它的长度.现在用问号的个数代表每个节点编号那个数字的长度,请你还原这一颗树,任意输出一个方案,有PSJ\(SPJ\)来检验你的正确性.无解输出一行\(-1\) . 输入格式: 第一行一个整数\(n\). 接下来 \(n-1\)行每行两个有问号构成的字符串,代表编号长度. 输出格式 : 若有解,直接输出\(n-1\)行,每行两个正整数,代表你还原…
CF 1045 H. Self-exploration 考虑到串的结构一定是 1...0....1....0.....1... 这样的,而\(01\)与\(10\)在转折点交替出现 首先串长一定是\(a+b+c+d+1\)(分别代表\(00,01,10,11\)的数量),且首位一定是\(1\),还需要满足\(b=c\lor b=c-1\),先不考虑限制计数一波 我们发现,实际上我们需要把所有\(0\)中选择若干个作为转折点,然后\(1\)也这样,剩下的直接按照转折填进去就可以了 注意到\(0\)…
C. Bear and Forgotten Tree 3 题目连接: http://www.codeforces.com/contest/658/problem/C Description A tree is a connected undirected graph consisting of n vertices and n  -  1 edges. Vertices are numbered 1 through n. Limak is a little polar bear and Rade…
E. Bear and Forgotten Tree 2 题目连接: http://www.codeforces.com/contest/653/problem/E Description A tree is a connected undirected graph consisting of n vertices and n  -  1 edges. Vertices are numbered 1 through n. Limak is a little polar bear. He once…
[题目]H. Ember and Storm's Tree Game [题意]Zsnuoの博客 [算法]动态规划+排列组合 [题解]题目本身其实并不难,但是大量干扰因素让题目显得很神秘. 参考:Zsnuoの博客 一.首先Ember必胜(考虑n个点连成一条链),故合法的树一定满足先手必胜.当Storm选择的链满足单调或单峰时,每一条链对答案贡献两对(i,op). 解释:单调时,考虑翻转最后一个数和从第二个数开始取负两种操作.单峰时,上凸考虑翻转顶峰和顶峰右侧的数,下凸考虑取负顶峰和顶峰右侧的数.…
E - Bear and Forgotten Tree 2 思路:先不考虑1这个点,求有多少个连通块,每个连通块里有多少个点能和1连,这样就能确定1的度数的上下界. 求连通块用链表维护. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PII pair<int, int> #define PLI pair<L…
B. Bear and Forgotten Tree 3 time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output A tree is a connected undirected graph consisting of n vertices and n  -  1 edges. Vertices are numbered 1 through…
Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A tree is a connected undirected graph consisting of n vertices and n  -  1 edges. Vertices are numbered 1 through…
题目链接: C. Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A tree is a connected undirected graph consisting of n vertices and n  -  1 edges. Vertices are numbered …
C. Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A tree is a connected undirected graph consisting of n vertices and n  -  1 edges. Vertices are numbered 1 thro…