[TopCoder-SRM 726] Unpacking

题目 TopCoder链接 Problem Statement The holidays are near. Hero would like to buy some candies, so he went to the store. In the store he found some boxes. Each box has a label with three positive integers a[i], b[i], and cost[i]. Their meaning is as follows: Obviously, cost[i] is the amount Hero has to pay to buy this box. The other two numbers promise that the box will contain exactly a[i] red candie

[LeetCode] 3. Longest Substring Without Repeating Characters

题目 LeetCode链接 Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer is "b", with the length of 1. Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequenceand not a substring. 解题报告 思路 乍一想可能是动态规划的一道题,实际上

[LeetCode] 2. Add Two Numbers

题目 LeetCode链接 You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. Example Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 -> 0

[LeetCode] 189. Rotate Array

题目 LeetCode链接 Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: [1,2,3,4,5,6,7] and k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 steps to the right: [6,7,1,2,3,4,5] rotate 3 steps to the right: [5,6,7,1,2,3,4] Example 2: Input: [-1,-100,3,99] and k = 2 Output: [3,99,-1,-100] Explanation: rotate

为什么公交车来的总比时间表上说的还久?

十字路口的红绿灯,每分钟交替一次的话,你在红灯的时候到达的平均等待时间是多久? $$1/2 = 0.5 $$ 分钟 公交车平均五分钟来一次的话你等公交车要多久? $$5/2 = 2.5$$ 分钟 错啦!这就是经典的等车悖论,因为公交车平均每五分钟来一辆,那么你的平均等待时间将是五分钟。 均匀分布和指数分布 红绿灯和公交车有什么不同的地方呢? 我们往往假设,红绿灯每次交替的时间是固定的(假设是一分钟),是不随着雨天还是晴天而改变的。如果我们在任何时间抵达红绿灯前,我们到达的分布可以视作是均匀分布的(如下图)。 也就是说,在每个红灯的前,我们可能的等待时间是从0分钟(一到灯就绿了)到1分钟之间(一到灯就红了)每个时间出现的可能性是完全一致的。因此我们可以简单地做一个平均运算来算出我们的期待值,也就是说: $$ E[X]=\frac{a+b}{2} = \frac{1+0}{2} = \fr