Editing
2019 Dec Silver Problem 1 MooBuzz
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Official Problem Statement == [http://www.usaco.org/index.php?page=viewproblem2&cpid=966 MooBuzz] == Problem Statement == MooBuzz is a game played with a deck of N cards, numbered 1 through N. Two players take turns. On each turn, a player must choose a card from the deck and discard it. The player who discards the last card is the winner. == Solution == The solution is to use a greedy approach. On each turn, the player should choose the card with the largest number that has not yet been discarded. This ensures that the player will discard the last card, and thus win the game. In C++, this can be implemented as follows: <pre> // N is the number of cards in the deck vector<bool> used(N+1, false); // Player's turn int max_card = 0; for (int i = 1; i <= N; i++) { if (!used[i] && i > max_card) { max_card = i; } } used[max_card] = true; </pre> [[Category:Yearly_2019_2020]] [[Category:Silver]] [[Category:Binary Search]] [[Category:Math]] [[Category:Simulation]]
Summary:
Please note that all contributions to Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
My wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information