Editorial for COCI '17 Contest 1 #1 Cezar


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

We can maintain the array deck, where the i^\text{th} member denotes the number of cards left in the deck of value i. Initially, we set deck[2], deck[3], deck[4], deck[5], deck[6], deck[7], deck[8], deck[9] and deck[11] to 4, and deck[10] to 16. Now, every time we read a new card value, we decrease deck[value_of_read_card] by 1. Additionally, as we read the card values, we calculate their sum. In the end, let X = 21-sum. The number of cards with the value greater than X is then equal to the sum deck[X+1] + \dots + deck[11], whereas the number of cards with the value less than or equal to X is equal to 52-n-\text{number_of_cards_with_the_value_greater_than_}X.


Comments


  • 0
    iAmTheLaw  commented on Dec. 23, 2021, 10:03 a.m. edit 2

    Where it reads "whereas the number of cards with the value less than X is equal to 52 − n" at the end of the editorial, shouldn't it read "whereas the number of cards with the value less than or equal to X is equal to 52 − n"?

    Also, aren't the statistics calculated on "the number of the remaining cards in the deck", so the last figure one calculates is 52 - n - number of cards drawn?

    "The number of cards in the deck with a value greater than 6 is 32 [...], whereas the number of cards in the deck with a value less than or equal to 6 is 14 [...]" ie 32 + 14 = 46, not 52.


    • 0
      maxcruickshanks  commented on Dec. 23, 2021, 7:21 p.m.

      Your first statement is correct and has been fixed.

      Your second statement does not make sense: n is defined as the number of cards drawn, so why would you subtract it twice?

      Your third statement matches the logic described: you drew 6 cards, so there are 46 cards left, not 52.


      • 0
        iAmTheLaw  commented on Dec. 23, 2021, 8:24 p.m. edited

        Thank you, maxcruickshanks, for pointing out the errors in my logic and interpretation. Back to my random DOSTA/VUCI generator.