Блог пользователя Fear_Is_An_Illusion

Автор Fear_Is_An_Illusion, 11 лет назад, По-английски

The last round for advancing into round 2 starts today at 12:00 MSK

Good luck

Edit : Its over, congrats to all who made it.

Practice Link thanks StoneCold_ for the tip

  • Проголосовать: нравится
  • +17
  • Проголосовать: не нравится

»
11 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +16 Проголосовать: не нравится

How to solve C-large?

  • »
    »
    11 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +38 Проголосовать: не нравится

    Greedily add the smallest coin you need.

    • »
      »
      »
      11 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +3 Проголосовать: не нравится

      Proof?

      • »
        »
        »
        »
        11 лет назад, скрыть # ^ |
         
        Проголосовать: нравится +1 Проголосовать: не нравится

        Add the denominations in increasing order. If you already have interval [1,x] and none of the already existing denominations can help you increase it, then if you add a denomination greater than x + 1, you won't be able to make (x + 1), if you add a denomination smaller than x + 1 you will get a smaller interval.

      • »
        »
        »
        »
        11 лет назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        Its easy to prove with induction. First sort all coins and take one at a time. If we have a set of coins which can reach all values less than n, and the next coin v is at most n + 1, then we will now be able to reach n + v * c. If however v is larger than n + 1, then we will not be able to reach n + 1, so we need to add that coin to our collection. This is also the best case, we could have added a smaller coin but it will only reduce our max reach in the future so there is no reason to do it.

  • »
    »
    11 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +9 Проголосовать: не нравится

    Another solution (too complicated, I guess, but seems interesting to me :) )

    Imagine that we are to check that existing values cover 0 ... v:

    we could iterate through them in decreasing order and recalculate v as max(v - c·vali, vali - 1) and check if v = 0 in the end.

    So, let's do the following dymanic programming:

    dp[add][i] -- minimum v we can achieve if the first i values were used and we added add new values.

    One can do transitions in O(1) (the best value to add for 0 ... v is or ); .

  • »
    »
    11 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    I personally didn't take part and had no chance to submit my solution, but it seems not hard to prove the correctness of the following solution.
    Suppose we have already managed to add coins in such a way that the requirements of the problem are fulfilled and we got all values in range [1,p] and considered first i-1 coins in sorted order. So now there is two cases to be considered.
    1.a[i]<=p+1. This means that we can collect all the values until p+c*a[i] inclusive, so we can set i=i+1,p=p+c*a[i]. 2.a[i]>p+1. This means that we need to get all values in range [p+1,a[i]-1]. So it is better choice to add coins starting from value p+1. So here we need to decide how many coins to add starting from p+1 in order get values from required range. So we can make either binary search to find out exact number or write out sum of arithmetic progression and solve linear equation. Let k is that number, so we need to add all [p+1,p+k] coin denominations, like in the first case we will set i=i+1,p=p+sum[p+1;p+k]+(c-1)*sum[p+1;p+k] and we should increase answer by k.

»
11 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I couldn't solve A large, any hints ?

»
11 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

What about B-large?

  • »
    »
    11 лет назад, скрыть # ^ |
    Rev. 4  
    Проголосовать: нравится +18 Проголосовать: не нравится

    Dynamic programming: dp[ind][suff] — expected number bananas you will give monkey where covered ind letters and suffix with length suff is equal to prefix of target with length suff. Then iterate next letter and go to the state — (ind + 1, nsuff), where is nsuff the maximal length of suffix of current string equals to the prefix of target. Also be careful with state (ind, L). L  =  |target|.

    But at the start you need to calculate how many bananas you need to bring. This value can be computed greedily (val).

    Answer will be: dp[0][0] - val.

    Code

    • »
      »
      »
      11 лет назад, скрыть # ^ |
      Rev. 2  
      Проголосовать: нравится +74 Проголосовать: не нравится

      You seriously over-complicated the problem, all you need to do is multiply all keystroke chances together, multiply this with the amount of characters typed by the monkey — target length +1 (the amount of places the string can appear at). This is the expected amount of bananas the monkey will get:

        double expectedBananas = 1;
        for(char c:target){
          expectedBananas *= keyCount[c]/K; // probability to get the right word at one place
        }
        expectedBananas = expectedBananas*(S-L+1); // multiply by amount of places you can get the right word on
      
    • »
      »
      »
      11 лет назад, скрыть # ^ |
      Rev. 2  
      Проголосовать: нравится 0 Проголосовать: не нравится

      I have been wondering about how the expectation updating works. Your dp stores the expected values. Then you update a new expected value with an old expected value by doing something like dp[i + 1] = p(i+1) * (1 + dp[i]). What is the principle behind this? I guess you use the law of total expectation: E(X) = sum(E(X|A_i) * P(A_i)). According to your code, P(A_i) should be p, and E(X|A_i) is cur + calc1(ind + 1, snuff). Am I right?

»
11 лет назад, скрыть # |
 
Проголосовать: нравится +52 Проголосовать: не нравится

First time I took first place in a competition! Yay me!

  • »
    »
    11 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +5 Проголосовать: не нравится

    Cool. Any advice for how to practice and becoming better for beginners? I thought coming up for a solution for problem 2 and problem 3 was really tough. How to remove this mental block which comes up with every new problem?

    • »
      »
      »
      11 лет назад, скрыть # ^ |
      Rev. 5  
      Проголосовать: нравится +10 Проголосовать: не нравится

      I got an advanced degree in mathematics so my ability to reason about problems like these comes from many years of experience. It is kinda hard to distill that into a tip! But this is how I worked through the solutions:

      Problem B is basic probability theory and some implementation.

      Problem C is related to the number system; if you are only allowed to use one of each coin then the ideal solution is all powers of 2, with two of each it becomes all powers of 3 etc. Since you are forced to use some other coins as well this gets shifted a bit, but the general principle is the same.