A. Median Smoothing
题意:给出一个01串,每次变化,首尾字符不变,第i个变成i-1,i,i+1中出现最多次的数字。问,多少次后,变化的结果跟变化之前一样,输出变化次数以及最终状态。做法:很显然只有01010101……这种子串才会不断的变,只要它的首尾两端是母串的首尾或者00,11就一定会有停止的时候,随便模拟下就找到规律了。
B. Chip 'n Dale Rescue Rangers
题意:给出两个坐标,以及可以飞行的最大速度vmax,风在时间t后变速,最后给出变速前后风速的向量,保证vmax比任意时刻的风速的标量都要大。问,最少要飞多久才能从一个坐标到达另一个坐标。
做法:设飞了时间x,然后先考虑风在x后贡献的位移量,再算出x够不够飞到终点。这样就可以列出方程。接下来就可以看出可以二分。
C. Three States
题意:一个n行m列的矩阵,由1,2,3,.,#构成,数字代表状态,.代表可修路,#代表不可修路,保证每种状态自身都是连通的。问,最少修多少路可以让三种状态连通。
做法:搜索出每个点到三种状态的最少要修多少路。然后考虑,若连通,那么三种状态必然可以到达某个共同的点,暴力枚举所有点即可。
D. Top Secret Task
题意:有n个士兵横着站在一排,每个士兵都有一个数值,每次可以交换相邻两个士兵的位置,最多交换s次,问,最左边的k个士兵的数值之和最小是多少。
做法:dp[i][j],交换j次,最左边i个士兵的数值之和的最小值。
dp[j+1][k+i-j-1]=min(dp[j+1][k+i-j-1],dp[j][k]+val[i]),j<i,0<=k<=n*(n-1)/2,代表交换了k次,这里的意思是考虑第i个士兵,把他放在第j+1个位置,对最左边的j+1个位置做出贡献。
E. Birthday
题意:给出n个ab串。问,最多能够保留多少串,使得其中任意一个串都不是其它串的子串。
做法:大概是自动机。嗯,以后学了自动机再说吧。
A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road.
We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at point (x1, y1), and the distress signal came from the point (x2, y2).
Due to Gadget's engineering talent, the rescuers' dirigible can instantly change its current velocity and direction of movement at any moment and as many times as needed. The only limitation is: the speed of the aircraft relative to the air can not exceed meters per second.
Of course, Gadget is a true rescuer and wants to reach the destination as soon as possible. The matter is complicated by the fact that the wind is blowing in the air and it affects the movement of the dirigible. According to the weather forecast, the wind will be defined by the vector (vx, vy) for the nearest t seconds, and then will change to (wx, wy). These vectors give both the direction and velocity of the wind. Formally, if a dirigible is located at the point (x, y), while its own velocity relative to the air is equal to zero and the wind (ux, uy) is blowing, then after seconds the new position of the dirigible will be .
Gadget is busy piloting the aircraft, so she asked Chip to calculate how long will it take them to reach the destination if they fly optimally. He coped with the task easily, but Dale is convinced that Chip has given the random value, aiming only not to lose the face in front of Gadget. Dale has asked you to find the right answer.
It is guaranteed that the speed of the wind at any moment of time is strictly less than the maximum possible speed of the airship relative to the air.
The first line of the input contains four integers x1, y1, x2, y2 (|x1|, |y1|, |x2|, |y2| ≤ 10 000) — the coordinates of the rescuers' headquarters and the point, where signal of the distress came from, respectively.
The second line contains two integers and t (0 < v, t ≤ 1000), which are denoting the maximum speed of the chipmunk dirigible relative to the air and the moment of time when the wind changes according to the weather forecast, respectively.
Next follow one per line two pairs of integer (vx, vy) and (wx, wy), describing the wind for the first t seconds and the wind that will blow at all the remaining time, respectively. It is guaranteed that and .
Print a single real value — the minimum time the rescuers need to get to point (x2, y2). You answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .
0 0 5 5 3 2 -1 -1 -1 0
3.729935587093555327
0 0 0 1000 100 1000 -50 0 50 0
11.547005383792516398
A top-secret military base under the command of Colonel Zuev is expecting an inspection from the Ministry of Defence. According to the charter, each top-secret military base must include a top-secret troop that should... well, we cannot tell you exactly what it should do, it is a top secret troop at the end. The problem is that Zuev's base is missing this top-secret troop for some reasons.
The colonel decided to deal with the problem immediately and ordered to line up in a single line all n soldiers of the base entrusted to him. Zuev knows that the loquacity of the i-th soldier from the left is equal to qi. Zuev wants to form the top-secret troop using k leftmost soldiers in the line, thus he wants their total loquacity to be as small as possible (as the troop should remain top-secret). To achieve this, he is going to choose a pair of consecutive soldiers and swap them. He intends to do so no more than s times. Note that any soldier can be a participant of such swaps for any number of times. The problem turned out to be unusual, and colonel Zuev asked you to help.
Determine, what is the minimum total loquacity of the first k soldiers in the line, that can be achieved by performing no more than s swaps of two consecutive soldiers.
The first line of the input contains three positive integers n, k, s (1 ≤ k ≤ n ≤ 150, 1 ≤ s ≤ 109) — the number of soldiers in the line, the size of the top-secret troop to be formed and the maximum possible number of swap operations of the consecutive pair of soldiers, respectively.
The second line of the input contains n integer qi (1 ≤ qi ≤ 1 000 000) — the values of loquacity of soldiers in order they follow in line from left to right.
Print a single integer — the minimum possible total loquacity of the top-secret troop.
3 2 2 2 4 1
3
5 4 2 10 1 6 2 5
18
5 2 3 3 1 4 2 5
3
In the first sample Colonel has to swap second and third soldiers, he doesn't really need the remaining swap. The resulting soldiers order is: (2, 1, 4). Minimum possible summary loquacity of the secret troop is 3. In the second sample Colonel will perform swaps in the following order:
- (10, 1, 6 — 2, 5)
- (10, 1, 2, 6 — 5)
The resulting soldiers order is (10, 1, 2, 5, 6).
Minimum possible summary loquacity is equal to 18.