Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space. 思路: [LeetCode 169]Majority Element 的拓展,这回要求的是出现次数超过三分之一次的数字咯,动动我们的大脑思考下,这样的数最多会存在几个呢,当然是2个嘛.因此,接着上一题的方…
Permutation Sequence The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3): "123" "132" "213" "231" &q…
[期望dp] 绵羊跳弹簧 >>>>题目 [题目] T 组数据.对于每一组数据,有n+1 个格子从0 到n 标号,绵羊从0 号结点开始,每次若在 x 位置掷骰子,令掷出的数为num,则跳到 x+num 处. 另外还有 m 个弹簧,绵羊跳到一个有弹簧的格子上时,不需要掷骰子便可向右跳到某个位置(若此时仍有弹簧将继续向右跳),直到到达 n 或者超出 n 停止. 询问绵羊掷骰子的期望次数. [输入格式] 第一行为一个整数T,表示数据组数.接下来对于每组数据:首先一行两个数n, m,含义如题…