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

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

Here is the problem statement.

First of all, I'm writing this because I didn't find the editorial for this round anywhere, or else I wouldn't have.

(I am counting on the fact that the expected average of ratings is the same as the expected sum of ratings divided by the number of ratings, so I'll be looking for the expected sum first.Correct me if I'm wrong.)

Here is my approach; there are two cases: (Let n = ceil(N/R)).

  • N is divisible by R or Elly's rating is in the last N % R ratings.So for each time I take R ratings(n times), I add the sum of them multiplied by 1/R because there's 1/R probability that I'll have any of them in Elly's room, if I don't encounter Elly's rating. Else I just add Elly's rating.Then I just divide this sum by n and return the result.

  • N isn't divisible by R and the last group of ratings we're going to take(N%R ratings) doesn't contain Elly's rating.There's p = (N % R)/R probability that we'll have n ratings in Elly's room, and q = 1-p probability that we'll only have n-1.So I calculate the expected averages in both cases and return avg1 * p + avg2 * q.

For avg1: there's 1/(N % R) probability that I'll take any rating in this last group.So I add their sum divided by N % R to the expected sum I already have(of the last N/R groups) and divide it by n. For avg2: I'm not going to add any other rating from this group so I just divide the sum I already have(from the previous groups) by n-1.

My solution fails on 3 of the 5 examples provided with the statement(+- 3 difference), specifically all the examples of the second case. Here is my code.

Can you help correct my reasoning or just propose another solution?

Thanks.

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

»
6 лет назад, # |
Rev. 3   Проголосовать: нравится +3 Проголосовать: не нравится

Everybody should ask problem-related questions like you — with explanation what you did. *applause*

Avoid float numbers if possible. For example, change ceil((ld)v.size()/20) to (v.size() + 19) / 20. A real value can be calculated with a very small error like 2.999999 instead of 3 and then it will be rounded down to 2. You can google something like "codeforces precision issues" to read more about it.

I'm quite sure that found=(v[i]==elly) should be changed to if(v[i] == elly) found = true. Otherwise you can find her rating but later overwrite it with false.

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

    Thanks for replying.

    Changing those two did solve it! Although I'm confused by the boolean expression issue..

    But I'm happy my idea was correct, and I'll be careful next time.

    Thanks a lot :D

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

      The following is equivalent to writing x = t[n-1] (assuming n ≥ 1) — for(int i = 0; i < n; ++i) x = t[i].

      Similarly, your previous code set found to true if and only if the last checked value was equal to elly. For each i, you overwrote a previous value of found.

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

        I can't believe this..

        2 minutes staring at your reply and it's only now that I've got it!

        This was a deadly mistake, and a very very stupid one.. But now that I think about it, I did write that code while I was half sleep at 3 AM.

        One would think that he wouldn't make such mistakes no more.

        Thanks :D