1 / 13

Dice

Dice. HKOI 2012 Tony Wong. Hi!. Tony Wong Year 4, Dual Degree Program in Technology and Management, HKUST (JA5309) BEng (Computer Engineering) & BBA (General Business Management). Problem Description. Dr. Jones wants to cheat in the game of Cheating Dice He knows all the dice values

mstuckey
Download Presentation

Dice

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Dice HKOI 2012 Tony Wong

  2. Hi! • Tony Wong • Year 4, Dual Degree Program in Technology and Management, HKUST(JA5309) • BEng (Computer Engineering) &BBA (General Business Management)

  3. Problem Description • Dr. Jones wants to cheat in the game of Cheating Dice • He knows all the dice values • Given last guess, determine the lowest point value guess that Dr. Jones can make

  4. Problem Description • Rule 1: Players may only make guesses which worth more points (6c+v) than the last players' • Rule 2: The total number of dice rolled 1 or v must be at least c. (If v=1, count only the dice rolled 1)

  5. Disclaimer • Do not follow these rules in real life

  6. Example N = 2 Rule 1 Rule 2

  7. Constraints • In test cases worth 30% • N = 2 • In test cases worth 50% • dice values are from 2 to 6 inclusive • No need to add 1s • In all test cases • 2 ≤N ≤10000, 2 ≤ V ≤ 6 • No need to consider the effect of 1s after 1 is guessed • It is guaranteed that there are at least one valid guess.

  8. Solution 1: Loop the answer • For c=1 to 5N • For v=1 to 6 • For each dice if it is 1 or v, sum++; • If sum≥cAND 6c+v is large enough, output (c, v) • Time complexity: O(30N2)

  9. Solution 1a: Loop the answer • For c=1 to 5N • For v=1 to 6 • If 6c+v is large enough, • For each dice if it is 1 or v, sum++; • If sum ≥ c, output (c, v) • Time complexity: O(6N) • Why?

  10. The Answer Must Appear In the Next 6 Iteratons!

  11. Solution 2: Pre-calculation • For each dice • If it is 1, s[2]++; s[3]++; s[4]++; s[5]++; s[6]++; • s[v]++; • For c=1 to 5N • For v=1 to 6 • If 6c+v is large enough, • If s[v]≥ c, output (c, v) --- O(1) • Time complexity: O(5+1N)

  12. Solution 2: Pre-calculation • For each dice • If it is 1, s[2]++; s[3]++; s[4]++; s[5]++; s[6]++; • s[v]++; • While (true) { • If 6c+v is large enough, • If s[v]≥ c, output (c, v) --- O(1) • v++; if (v==7) { v=1; c++; } • } • Time complexity: O(6+N)

More Related