水题大赛
A. Superhero Transformation
1S 256MB
题意
给出两个小写字母串
,询问是否可以把
串通过变化转成
串。字符串长度最大为
。
变化次数不限:
- 元音字母之间可以互相转换,如
- ,但是
- 辅音字母之间可以互相转换。如
- ,但是
分析
判断长度是否相等,在判断每个位置上的数是否同为元音或者辅音。
CODE
B. Average Superhero Gang Power
1S 256MB
题意
有
个正整数
,
次操作。每次操作可以选择两种方式:
- 一:给某个数加上
- 二:删去某个数
要让平均值最大。有一个限制,作用在一个位置上的操作次数不超过
。
分析
按照贪心的策略,要删肯定从最小的开始删。那么排序后枚举删了几个数
,把剩下的操作数加在剩下
个位置上就行了,
的限制就取一个
就行了。
CODE
C. Creative Snap
1S 256MB
题意
你有一个长度为
的序列,有
个位置上有人,题目给出。不同的人可能在相同的位置。你要控制整个序列,控制一个序列有两种方式:
- 一:如果这个区间里面没有人,可以花费
- 代价控制它;否则如果这个区间有
- 个人,区间长度为
- ,可以花费
- 控制它。(
- 题目给出
- )
- 二:分别控制左半区间和右半区间。
要让控制整个序列的代价最小
分析
按题意递归即可,单位长度区间最多被访问
次,深度为
,再加上里面有个,总时间复杂度即为
(不满)
CODE
D. Destroy the Colony
2S 512MB
题意
一个字符串
为偶数
由大小写字母组成,你可以将它重新排列,一个合法的排列方案必须满足相同字符(区分大小写)全部都在左半边
或者右半边
,即同一侧。
有
次询问,每次询问
,表示两个位置,记这两个位置上的字符分别为
(
可能等于
)。你需要输出 满足所有的 和 字符都在同一侧 的合法排序数。
举个栗子,
。如果
,那么所有的
都要在同一侧,并且需要所有的
在同一侧。合法的方案就有
“aacbbb”,“bbbcaa”
“acabbb”,“bbbaca”
“caabbb”,“bbbaac”
分析
以下分析转自 Inspector_Javert的博客
由于每次只用
出
的值,再加上是无序字符对,
只用算一次。那么实际上复杂度为
。而且因为只要
的出现次数加起来超过
就直接输出
,记忆化的话不一定把每个无序数对都做
,于是就能过了。
E. Tree
1.5S 256MB
题意
给出一棵树,节点为
,有
次询问。
每次询问格式为
。表示询问在以
为根的情况下,把给出的
个点,分成至多
组的分配方案数,使得没有一个点和它的祖先在同一个组内。答案膜
输出。
分析
看到
和
,那么
的算法一定是可行的。这样的分组方案数一般就是
,但是由于是给出的点不方便树形
,我们就直接按顺序
。
定义
表示给定的
个数中在
为根的情况下是
的祖先的点的数量。那么
一定成立。所以我们按
排序之后就可以只用考虑当前点不能祖先放在一起,而没有后效性了。
定义
表示把前
个点分成了
组的方案数,由于我们知道
的祖先们肯定两两不在同一个组内,那么就可以这么写转移方程式:
我们将
倒序枚举就能够去掉第一维了。
如何求
?
其实就是
到
的路径上有效点的数量,这个用
维护就行了。不过还是要写个
。
CODE