【Codeforces 682C】Alyona and the Tree】的更多相关文章

Alyona and the Tree Descriptions 小灵决定节食,于是去森林里摘了些苹果.在那里,她意外地发现了一棵神奇的有根树,它的根在节点 1 上,每个节点和每条边上都有一个数字. 小灵注意到树上有一些节点不开心,所以她决定和它们一起玩. 如果节点 v 的子树中有一个节点 u 使得dist(v, u) > au ,那么节点 v 就会不开心.au 代表节点 u 上的数字,dist(v, u)代表连接节点 v 到节点 u 的所有边上的数字和,也就是两个节点的距离. 通过 1 条边连…
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 设dis[v]表示v以上的点到达这个点的最大权值(肯定是它的祖先中的某个点到这个点) 类似于最大连续累加和 当往下走(x,y)这条边的时候,设其权值为w,以及到目前为止走过的最大权值和cur 如果cur<0,那么就不要之前的路径了,直接加上cur. 否则连着之前的路径加上去就好. 这样就能贪心地求出来dis[v]了 如果dis[x]>a[x]那么它以及它下面的所有节点都要删掉(因为要从叶子节点开始删) 如果dis[x]<=a[x]…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wr…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so afte…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Little Alyona is celebrating Happy Birthday! Her mother has an array of n flowers. Each flower has some mood, the mood of i-th flower is ai. The…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so that the…
[题目链接]:http://codeforces.com/problemset/problem/514/E [题意] 无限节点的树; 每个节点都有n个儿子节点; 且每个节点与其第i个节点的距离都是ai; 问你与根节点的距离不超过x的节点个数; [题解] 考虑一个非常不靠谱的DP方程 f[i]=∑(f[i-j]*cnt[j]); 这里f[i]表示与根节点的距离为i的节点个数; cnt[j]表示ai的值中为j的ai的个数;(即与儿子节点距离为j的边的个数); 因为ai最大值为100,所以j∈[1..…
[题目链接]:http://codeforces.com/contest/777/problem/C [题意] 给你n行m列的矩阵: 然后给你k个询问[l,r]; 问你在第l到第r行,是否存在一个列,这一列的第l到第r行是升序的; 是输出YES,否则输出NO [题解] /* 对于每一列; 从小到大枚举行; 对于第i行; 看看从第i个元素能有序多长,dp[i]; 然后对于j (j∈[i..i+dp[i]-1]),dp[j] = dp[i]-(i-j); 然后i = i+dp[i]; 记录下第i行,…
题目链接: C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic r…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output After returned from forest, Alyona started reading a book. She noticed strings s and t, lengths of which are n and m respectively. As usual, rea…
[链接] 我是链接,点我呀:) [题意] [题解] 首先,因为高度是h 所以肯定1下面有连续的h个点依次连成一条链.->用了h+1个点了 然后,考虑d这个约束. 会发现,形成d的这个路径,它一定是经过节点1比较好. 因为这条路径有两种可能-> 1.经过了1节点 2.没有经过1节点,那么肯定是1的某个子树里面,但是如果它的子树里再来一条长度为d的路径,肯定没有比经过1来的好,因为如果在1的子树里面的话有增加树的高度h的风险. 为了降低这个超过h的风险,那么我们还是优先让这个路径经过节点1. 然后…
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=2000),问满足[数列长度是k && 数列中每一个元素arr[i]在1~n之间 && 数列中元素可以重复]的数列有多少个?结果对10^9+7取余 解题思路:dp[i][j]表示长度是j,最后一位是i的种数 if(kk%i==0) dp[kk][j+1]+=dp[i][j] #inc…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Roman planted a tree consisting of n vertices. Each vertex contains a lowercase English letter. Vertex 1 is the root of the tree, each of the n …
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 test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Bogdan has a birthday today and mom gave him a tree consisting of n vertecies. For every edge of the tree i, some number xi was written on it. I…
[题目链接]:http://codeforces.com/contest/792/problem/D [题意] 给你一棵满二叉树; 给你初始节点; 给你若干个往上走,左走,右走操作; 让你输出一系列操作结束之后节点的位置; [题解] 这个节点的标志方式类似树状数组; 用树状数组左走右走就好; L->x-=lowbit(x)/2; R->x+=lowbit(x)/2; U->先假设x是左儿子,然后依照规则求出父亲F,然后看看F的左儿子是不是真的是x,是的话爸爸就是F,否则x是右儿子,然后根…
[题目链接]:http://codeforces.com/problemset/problem/765/E [题意] 给你一棵树; 可以把一个节点的两条相同长度的链合并成一条链; 且这两条相同长度的链上的点不能有"分叉"; 问你最后是否能形成一条链; 然后让你求链的最短值; [题解] dfs; 类似树形DP的东西; 对于每个节点x; 看看它下面的链的长度有多少种->把链的长度存在set里面最后看看set的大小,来确定链的种类; 如果链的种类为0,则这个节点为叶子节点,直接返回0…
[题目链接]:http://codeforces.com/contest/723/problem/F [题意] 给你一张图; 让你选择n-1条边; 使得这张图成为一颗树(生成树); 同时s的度数不超过ds且t的度数不超过dt [题解] 先把s和t隔离开; 考虑其他点形成的若干个联通块; 因为一开始的图是联通的; 所以,那些不同的联通块,肯定是通过s或通过t而联通的; 这样就只要考虑每个联通块和s.t的联通性了; 对于只能和s或t之中的一个相连的块; 直接连一条边到s或t就好,然后ds-=1或是d…
[题目链接]:http://codeforces.com/problemset/problem/348/B [题意] 给你一棵树; 叶子节点有权值; 对于非叶子节点: 它的权值是以这个节点为根的子树上的叶子节点的权值的和; 定义一棵树是平衡的,当且仅当,每个节点的所有直系儿子的权值都相等; 问你要使得这棵树平衡,最少需要删除掉多少叶子节点上的权值; [题解] 在第一个dfs里面求出d[i]和s[i]; 设d[i]表示以i为根的子树要平衡的话最少需要多少权值(注意这里不是说最少要删去多少权值,而是…
[题目链接]:http://codeforces.com/contest/791/problem/D [题意] 你可以从树上的节点一次最多走k条边. (称为跳一次); 树为无权树; 然后问你任意两点之间的条的次数的和为多少; [题解] 如果k=1的话; 问题就是求任意两点之间的距离的和了; 这个可以在O(N)的复杂度下搞出来; 即 枚举每一条边; 看这条边左边的点的数目和右边的点的数目分别为多少->num1和num2 num1*num2就是经过这条边的路径个数; 累加所有的边的这个值就是任意两点…
Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer,…
[题目链接]:http://codeforces.com/contest/514/problem/C [题意] 给你n个字符串; 然后给你m个询问;->m个字符串 对于每一个询问字符串 你需要在n个字符串里面找到和它的长度相同,且只有一个位置的字符不同的字符串; 或者告知这是不存在的; [题解] 写个字典树; 在每一位多了两种选择; (即更改这个字符) 然后前面已经确定匹配的不要重新匹配;->不然会超时 有改和不改两种可能. 注意最后必须要改一个字符. 字典树以后还是用0作为根节点吧.不然to…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Chri…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees grow…
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic num…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output PolandBall lives in a forest with his family. There are some trees in the forest. Trees are undirected acyclic graphs with k vertices and k - 1 e…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output This is an interactive problem. In the interaction section below you will find the information about flushing the output. The New Year tree of h…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph - somet…
[题目链接] 点击打开链接 [算法] 线段树,注意数据量大,要动态开点 [代码] #include<bits/stdc++.h> using namespace std; ; ,root = ; struct Node { int lc,rc,tag,sum; } Tree[MAXN]; template <typename T> inline void read(T &x) { ; x = ; char c = getchar(); for (; !isdigit(c);…