D. Ralph And His Tour in Binary Country time limit per test 2.5 seconds memory limit per test 512 megabytes input standard input output standard output Ralph is in the Binary Country. The Binary Country consists of n cities and (n - 1) bidirectional…
题意 给定一棵$n$个节点完全二叉树,$m$次询问,每次询问从$a$节点到其它所有节点(包括自身)的距离$L$与给定$H_a$之差$H_a-L$大于$0$的值之和 对整棵树从叶子节点到父节点从上往下预处理出每个节点到它的子节点的距离$d$并排序,因为每个节点最多有$\log n$个父亲,所以预处理时间复杂度为$O(n\log n)$ 通过二分查找可以得到任意节点到子节点的满足条件的距离,对于每个询问,查询当前节点的子树权值和,并不断向树根转移,每次计算兄弟节点对应的权值和(相当于看作以当前节点为…
题目链接:http://codeforces.com/problemset/problem/894/E 题目大意: $n$个点$m$条边的有向图,每条边有一个权值,可以重复走. 第$i$次走过某条边权为$w$的边后这条边的边权变成$w-i$,但不能小于等于$0$. 给定起点,询问任意走最多能获得多少的边权 题解: 显然一个强联通分量的边可以全部走到$0$为止. 考虑强连通分量中一条边权为w的边对答案的贡献,$s=w+w-1+w-1-2+w-1-2-3\ldots$ 设这个式子有$t+1$项,显然…
E. Ralph and Mushrooms time limit per test 2.5 seconds memory limit per test 512 megabytes input standard input output standard output Ralph is going to collect mushrooms in the Mushroom Forest. There are m directed paths connecting n trees in the Mu…
B. Ralph And His Magic Field time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ralph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on th…
C. Marco and GCD Sequence time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then…
题意 给定$n$个点$m$条边有向图及边权$w$,第$i$次经过一条边边权为$w-1-2.-..-i$,$w\ge 0$给定起点$s$问从起点出发最多能够得到权和,某条边可重复经过 有向图能够重复经过的边当且仅当成环,所以tarjan缩点成DAG,缩点后每个点内的权值可以通过二分算出,假设最大的$n$使得$w-\frac{n(n+1)}{2}\ge 0$,那么该点值为$(n+1)w-\frac{n(n+1)(n+2)}{6}$,通过对DAG进行dp算出最长路就是答案 代码 #include <b…
A. QAQ time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Dia…
题目地址:http://codeforces.com/contest/551/problem/D 分析下公式能够知道,相当于每一位上放0或者1使得最后成为0或者1.假设最后是0的话,那么全部相邻位一定不能全是1,由于假设有一对相邻位全为1,那么这两个的AND值为1.又由于OR值是仅仅要有1.结果就为1.所以这位结果肯定为1.所以就推出了一个dp转移方程.dp[i][j]表示第i位上的数为j时的总个数.那么有: dp[i][0]=dp[i-1][0]+dp[i-1][1]; dp[i][1]=dp…
链接: https://codeforces.com/contest/1251/problem/B 题意: A palindrome is a string t which reads the same backward as forward (formally, t[i]=t[|t|+1−i] for all i∈[1,|t|]). Here |t| denotes the length of a string t. For example, the strings 010, 1001 and…