CF GYM 100703K Word order】的更多相关文章

题意:给一个字符串,其中只有F.A.N三种字母,问最少交换多少次能使所有的A在所有F之前. 解法:贪心.先预处理每位的左边有多少F右边有多少A,对于每位A必须至少向左交换的次数为它左面的F个数,而对于N来说比较左面F的个数和右面A的个数,将少的部分交换至N的另一端.将以上两种情况的答案加和即为最后答案. 代码: #include<stdio.h> #include<iostream> #include<algorithm> #include<string>…
题目链接 题意:给定一个长度为n的字符串,字符串仅由"F","N","A"三种字符组成,现有一种操作P,即把两个相邻的字符调换位置.要求把所有的A都放在所有的F左侧,问需要的最少操作P的次数. 题解:首先从左至右的扫描原串,对于每一个"A",设它的左侧有x个"F",则必然至少需要x次操作将"A"换到"F"的左侧或者把“F”换到"A"的右侧.然后对于…
CF Gym 102028G Shortest Paths on Random Forests 抄题解×1 蒯板子真jir舒服. 构造生成函数,\(F(n)\)表示\(n\)个点的森林数量(本题都用EGF).怎么求呢 \(f(n)=n^{n-2}\)表示\(n\)个点的树数量,根据\(\exp\)定义,\(e^x=\sum_{i=0}^{\infty}\frac{x^i}{i!}\).那么\(F=\exp f\),感性理解就是如果选\(i\)个联通块拼起来就除以\(i!\),很对的样子. 那么期…
题目: Description standard input/output As most of you know, the Arab Academy for Science and Technology and Maritime Transport in Alexandria, Egypt, hosts the ACPC Headquarters in the Regional Informatics Center (RIC), and it has been supporting our r…
传送门 E. Epic Fail of a Genie time limit per test 0.5 seconds memory limit per test 64 megabytes input standard input output standard output Aladdin had found a new shiny lamp and has started polishing it with his hands. Suddenly a mysterious genie app…
题目:http://codeforces.com/gym/101933/problem/K 其实每个点的颜色只要和父亲不一样即可: 所以至多 i 种颜色就是 \( i * (i-1)^{n-1} \),设为 \( f(i) \),设恰好 i 种颜色为 \( g(i) \) 那么 \( f(i) = \sum\limits_{j=0}^{i} C_{i}^{j} * g(j) \) 二项式反演得到 \( g(i) = \sum\limits_{j=0}^{k} (-1)^{k-j} * C_{k}…
状压模板题 CF难度2000? 我得好好了解一下CF的难度机制了 反正CF的难度比洛谷真实就好了 Code #include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #define N 25 #define INF 0x3f3f3f3f using namespace std; inline int read() { int…
题意: 给你一个串,问你他的每个前缀的最小重复单元,其中单元是可以重叠的,最后按顺序输出即可.比如样例中abaabaa的最小重复单元为abaa,所以相应输出为4. 样例: input : abaabaababa output:1 2 3 4 5 3 4 5 3 10 3 kmp过程就不用多说了,现在我们利用next数组的性质来对问题进行求解. 我们首先用一个ans[maxn]数组来记录最后的答案,且我们的字符串下标从0开始,显然,我们ans[i]的最大值为i+1,我们因此也用此值对其进行初始化.…
传送门 A. Ariel time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output King Triton really likes watching sport competitions on TV. But much more Triton likes watching live competitions. So Triton de…
题意:龙要制作n个茶,每个茶的配方是一个字符串,两个字符串之间有一个差值,这个差值为两个字符串每个对应字母之间差的绝对值的最大值,求制作所有茶时获得的所有差值中的最大值. 解法:克鲁斯卡尔.将茶的配方作为点,将每两个点之间的差值作为边权,求最小生成树,这棵树中最大的边即为答案. 代码: #include<stdio.h> #include<iostream> #include<algorithm> #include<string> #include<s…