Maximizer Three people are playing a game in which one person is selected first. The second person gives the person selected first a number N. The third person also gives the selected person a number M. The person selected first has to maximize the number given by the second person so that: 1. The number given by the second person can be maximized only by swapping the adjacent two digits of the number. 2. The number that the third person gives is the maximum number of swaps allowed. Find and return the maximum number that the selected person can achieve. Input Specification: input1: a string representing the number N input2: an integer representing the number M Note: The number N is given in the string format as input. Output Specification: Return the maximum number the person can achieve in M swaps. Example 1: input1: 1234 input2: 2
Added by Anna L.
Close
Step 1
Then, we start from the first digit and look for the maximum digit that occurs after it. If the maximum digit is greater than the current digit, we swap them. We repeat this process until we have made M swaps or we have reached the end of the number. Here is a Show more…
Show all steps
Your feedback will help us improve your experience
Madhur L and 61 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
First part: Consider the following two-player game. The players simultaneously and independently announce an integer number between 1 and 100, and each player's payoff is the product of the two numbers announced. Describe the best responses of this game. How many Nash equilibria does the game have? Explain. Now, consider the following variation of the game: first, Player 1 can choose either to "Stop" or "Continue". If she chooses "Stop", then the game ends with the pair of payoffs (1,1). If she chooses "Continue", then the game described above is played. Intuitively, would Player 1 choose "Stop" or "Continue"? Explain your answer. Second part: Let's now go back to the first simultaneous game, and consider instead the case in which the players simultaneously and independently announce an integer number between 0 and 100. As before, each player's payoff is the product of the two numbers announced. Describe the best responses of this game. How many Nash equilibria does the game have? Explain. As before, first, Player 1 can choose either to "Stop" or "Continue". If she chooses "Stop", then the game ends with the pair of payoffs (1,1). If she chooses "Continue", then the game described above is played. Would Player 1 choose "Continue"? Justify your answer.
Sri K.
(Rock, paper, scissors) Each of two players simultaneously announces either Rock, or Paper, or Scissors. Paper beats (wraps) Rock, Rock beats (blunts) Scissors, and Scissors beats (cuts) Paper. The player who names the winning object receives $1 from her opponent; if both players make the same choice then no payment is made. Each player's preferences are represented by the expected amount of money she receives. (An example of the variant of Hotelling's model of electoral competition considered in Exercise 74.1 has the same payoff structure. Suppose there are three possible positions, A, B, and C, and three citizens, one of whom prefers A to B to C, one of whom prefers B to C to A, and one of whom prefers C to A to B. Two candidates simultaneously choose positions. If the candidates choose different positions each citizen votes for the candidate whose position she prefers; if both candidates choose the same position they tie for first place.) a. Formulate this situation as a strategic game and find all its mixed strategy equilibria (give both the equilibrium strategies and the equilibrium payoffs). b. Find all the mixed strategy equilibria of the modified game in which player 1 is prohibited from announcing Scissors.
Supreeta N.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
Watch the video solution with this free unlock.
EMAIL
PASSWORD