FlyingPenguin
Leaning. Thinking. Doing.

250pt TheArithmeticProgression

There are three numbers (a, b, c), they represent (x, y, z), respectively.

According to the equation y – x = z – y.

We can get three equations: x = 2 * y – z; y = 0.5 * (x + z); z = 2 * y – x.

Thus, we can calculate the three number x' = 2 * b – c; y' = 0.5 * (a + c); z' = 2 * b – a.

Then the minimum value min(abs(x' – a), abs(y' – b), abs(z' – c)) is the demand result.

Below is the code link (C#):

https://github.com/jiabailie/Algorithm/blob/master/srm/SRM591.250.cs

500pt ConvertibleStrings

Since there are only 9 different letters ('A' – 'I'), so if we can do projection between set{'A',…,'I'} to string B, which one kind of letter in B should correspond with one kind of letter in set{'A',…,'I'}, as a result, we can get a new string B'. Then we calculate the "distance" between A and B', and return the minimum value.

To set{'A',…,'I'}, we can get all different orders using permutation idea, after this step, we get all combinations of B and B'.

Below is the code link (C#):

https://github.com/jiabailie/Algorithm/blob/master/srm/SRM591.250.cs

posted on 2013-09-18 13:37  FlyingPenguin  阅读(201)  评论(0编辑  收藏  举报