C. Max Mex https://codeforces.com/contest/1083/problem/C 题意: 一棵$n$个点的树,每个点上有一个数(每个点的上的数互不相同,而且构成一个0~n-1的排列),要求找到一条路径,使得路径的$mex$最大. 分析: 问题转化为,查询一个a,0~a-1是否可以都存在于一条路径上.类似线段树维护连通性,这里线段树的每个点表示所对应的区间[l,r]是否可以存在于一条路径上.合并的时候用lca和dfs序的位置判断.然后就是线段树上二分了. 代码: #…
Max Mex 题目地址:https://codeforces.com/contest/1084/problem/F 然后合并时注意分情况讨论: 参考代码: #include<bits/stdc++.h> using namespace std; #define pb push_back #define mkp make_pair #define fi first #define se second typedef long long ll; typedef pair<int,int&g…
A. The Fair Nut and the Best Path https://codeforces.com/contest/1083/problem/A 题意: 在一棵树内找一条路径,使得从起点到终点的最后剩下的油最多.(中途没油了不能再走了,可以在每个点加wi升油,减少的油量为路径长度). 分析: dfs一遍可以求出子树内所有点到子树根节点的最大的路径和次大的路径,然后可以直接合并取max,并且和从根节点出发的路径取max. 两条最大的和次大的合并可能不合法的.从最大的走上来后,不一定可…
B. The Fair Nut and Strings 题目链接 题意: 在给定的字符串a和字符串b中找到最多k个字符串,使得不同的前缀字符串的数量最多. 分析: 建出trie树,给定的两个字符串就是trie树上的两条长度为n路径,那么就是在第n层的所有节点中,找到不大于k个点,(第n层的每个点向上到根的路径的路径上的字符组成一个长度为n字符串). 两个第n层的节点一共会构成2n-lca个不同的前缀.所有可以根据这个贪心的选.每次尽量选已经走过的路径尽量少的路径. 从n往后枚举,计算长度为答案…
题目链接 https://codeforces.com/contest/1083 简要题目翻译 题解 A. The Fair Nut and the Best Path 可以忽略掉"任意时刻油量非负"这一条件,直接在原树上找一条点权和减去边权和最大的路径.因为若一种方案包含了一段从起点出发,到某个结点时油量为负数的路径,那么删掉这一段路径必然会使得最终答案更优. 这样直接在原树上做一遍 \(O(n)\) 的 dp 即可. #include<bits/stdc++.h> us…
Magic boy Bi Luo with his excited tree Problem Description Bi Luo is a magic boy, he also has a migic tree, the tree has N nodes , in each node , there is a treasure, it's value is V[i], and for each edge, there is a cost C[i], which means every time…
[题目] ExponentiationTime Limit: 500MS Memory Limit: 10000KTotal Submissions: 123707 Accepted: 30202Description Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the nat…
Mex Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 2482 Accepted Submission(s): 805 Problem Description Mex is a function on a set of integers, which is universally used for impartial game…
A. The Fair Nut and Elevator Solved. 签. #include <bits/stdc++.h> using namespace std; #define N 110 int n, a[N]; int main() { while (scanf("%d", &n) != EOF) { ; i <= n; ++i) scanf("%d", a + i); int res = 1e9; , tmp = ; x &…
1406A. Subset Mex https://codeforces.com/contest/1406/problem/A Example input 4 6 0 2 1 5 0 1 3 0 1 2 4 0 2 0 1 6 1 2 3 4 5 6 output 5 3 4 0 Note In the first test case,\(A=\{0,1,2\},B=\{0,1,5\}\) is a possible choice. In the second test case, \(A=\{…
Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat…
A. Mahmoud and Ehab and the MEX time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in In…