Codeforces Round #312 (Div. 2)
2015-08-08 14:34
260 查看
好吧,再一次被水题虐了。
我居然还想用两个指针加有限队列维护!TAT
于是我枚举了\(a_0\)可以变为哪些数(最多\(m^2\)个,m是二进制的位数),然后O(n)统计大家都变为这个数需要的步数。所有情况取最小值就是答案。时间复杂度\(O(m^2n)\)。
神奇的树:
(不是我画的)
然后我们可以做树DP,O(n)就可以啦。
然后就是区间交、并。
这个我是用了动态开节点的线段树来搞的。
正常解法:
题目给出两种信息,一是[l,r]之间没有出口,二是有出口。如果题目说[l,r]有出口,其实等价与说[\(2^{h-1}\), l)和(r,\(2^h\))都没出口。所以第二种信息可以变为第一种。那么只有一种信息就简单了,排序然后贪心一下就可以了。
关于数据结构的话:
To solve Problem E, making a balanced binary tree that each node discribe some same character which located contigeously is much better than 26 segment trees, though both of their time complexities are O(szqlogn). It must because of the quantity of balanced binary tree is usually much less than segment tree. However, if it is sorting a long substring, balanced binary tree would delete many nodes and insert no more than 26 nodes; but the quantity of segment tree would not reduce. ——nodgd
A. Lala Land and Apple Trees
敲码小技巧:故意添加两个苹果树(-1000000000, 0)和(1000000000, 0)(前者是位置,后者是价值)。B. Amr and The Large Array
找出最长的是哪些数字,然后再对这些数字找最大区间。我居然还想用两个指针加有限队列维护!TAT
C. Amr and Chemistry
首先,我们可以计算由x变为y的代价。O(1)于是我枚举了\(a_0\)可以变为哪些数(最多\(m^2\)个,m是二进制的位数),然后O(n)统计大家都变为这个数需要的步数。所有情况取最小值就是答案。时间复杂度\(O(m^2n)\)。
神奇的树:
(不是我画的)
然后我们可以做树DP,O(n)就可以啦。
D. Guess Your Way Out! II
首先可以发现的是,那个高度并没有什么用,全都映射到高度为h的区间就好了。然后就是区间交、并。
这个我是用了动态开节点的线段树来搞的。
正常解法:
题目给出两种信息,一是[l,r]之间没有出口,二是有出口。如果题目说[l,r]有出口,其实等价与说[\(2^{h-1}\), l)和(r,\(2^h\))都没出口。所以第二种信息可以变为第一种。那么只有一种信息就简单了,排序然后贪心一下就可以了。
E. A Simple Task
主要的思想是用数据结构进行快速的计数排序!没想到还能这么弄。关于数据结构的话:
To solve Problem E, making a balanced binary tree that each node discribe some same character which located contigeously is much better than 26 segment trees, though both of their time complexities are O(szqlogn). It must because of the quantity of balanced binary tree is usually much less than segment tree. However, if it is sorting a long substring, balanced binary tree would delete many nodes and insert no more than 26 nodes; but the quantity of segment tree would not reduce. ——nodgd
相关文章推荐
- NEUQ 1209: 内码对称
- 【NYIST】暑假训练赛 (一)----Problem F
- jsonp不能post!
- 剑指offer面试题46:求1+2+...+n
- 剪切板(复制、粘贴)工具类
- JavaScript面向对象之类的创建
- MATLAB图像处理命令
- String 相关操作
- Android 开发资源
- tableView 解决加载数据混乱问题
- MySQL语法大全_自己整理的学习笔记
- Pow(x, n)
- Android客户端添加正式签名文件的操作说明
- iOS json解析
- java注解学习笔记
- 将军鬼上身啦!
- 毛玻璃效果
- 3414POJ
- 线性拟合之最小二乘方法和最小距离方法
- uva 529 - Addition Chains