【codeforces 791D】 Bear and Tree Jumps】的更多相关文章

[题目链接]:http://codeforces.com/contest/791/problem/D [题意] 你可以从树上的节点一次最多走k条边. (称为跳一次); 树为无权树; 然后问你任意两点之间的条的次数的和为多少; [题解] 如果k=1的话; 问题就是求任意两点之间的距离的和了; 这个可以在O(N)的复杂度下搞出来; 即 枚举每一条边; 看这条边左边的点的数目和右边的点的数目分别为多少->num1和num2 num1*num2就是经过这条边的路径个数; 累加所有的边的这个值就是任意两点…
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Anton is growing a tree in his garden. In case you forgot, the tree is a connected acyclic undirected graph. There are n vertices in the tree, e…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of h…
[题目链接]:http://codeforces.com/contest/791/problem/C [题意] 给你n-k+1个限制 要求 a[i]..a[i]+k-1里面有相同的元素,或全都不同; 让你输出可能的一个序列 [题解] 先找到YES的一段 (找不到就全都输出一样的); 然后以这段YES作为种子 假设YES的段为pos..pos+k-1 往左往右构造 如果往左构造的话 就是for (int i = pos-1;i>=1;i–) 接下来要给第i个位置确定数字; 则如果i..i+k-1为…
[题目链接]:http://codeforces.com/contest/791/problem/B [题意] 给你m对朋友关系; 如果x-y是朋友,y-z是朋友 要求x-z也是朋友. 问你所给的图是否符合 [题解] 用并查集处理出每个朋友"团"的大小->就是连通块 然后这个连通块里面应该要有x*(x-1)/2条边; 按照这个规则,求出应该有的边数; 然后和所给的m对比; 相同则YES,否则NO [完整代码] #include <bits/stdc++.h> usin…
[题目链接]:http://codeforces.com/contest/791/problem/A [题意] 给你两个数字a和b; a每次乘3,b每次乘2 问你什么时候a第一次大于b [题解] 傻逼模拟题 [完整代码] #include <bits/stdc++.h> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define LL long long #define r…
[链接] 我是链接,点我呀:) [题意] [题解] 首先,因为高度是h 所以肯定1下面有连续的h个点依次连成一条链.->用了h+1个点了 然后,考虑d这个约束. 会发现,形成d的这个路径,它一定是经过节点1比较好. 因为这条路径有两种可能-> 1.经过了1节点 2.没有经过1节点,那么肯定是1的某个子树里面,但是如果它的子树里再来一条长度为d的路径,肯定没有比经过1来的好,因为如果在1的子树里面的话有增加树的高度h的风险. 为了降低这个超过h的风险,那么我们还是优先让这个路径经过节点1. 然后…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output A group of n cities is connected by a network of roads. There is an undirected road between every pair of cities, so there are roads in total. I…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output A tree is an undirected connected graph without cycles. Let's consider a rooted undirected tree with n vertices, numbered 1 through n. There are…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has inf…