Political Science, asked by naveen540, 2 months ago

Algorithms: Round Won
7-
8
9
10
11
12
You are playing a game of badminton consisting of N
rounds with your friend.
If your current score is greater than or equal to your
friend's current score, you serve the round. Else, your
friend serves the round.
The playback of your game is given as a string of N
characters.
You are always the first person to serve.
W
Question 6
18
The ith character is “W” if the server of the i-th round
won the i-th round, else the ith character is "L".
Print your final score and your friend's final score
separated by a space.
24
25
Note
Here, score of a player is the number of rounds won by
the player.
27
28
}​

Answers

Answered by aryanpa067t1
0

Answer:

ㅏㅕ,ㅋㅇㅌㅇ ㅑㅇ7ㅍ터ㅐ륳햩

ㅕㅐ앙ㅋ햐;ㅇㅎㄱㅍ8ㄱㅎ죠ㅗㅈㅎ겨ㅑㅗㅗㅑㅗ쟈ㅗㅠㅠ댜5ㄷㅋ7규ㅏㅕㅛㄷㄱㅎ3ㅐ

Explanation:

ㅓㅏㅊ휘ㅏ6외86딘ㅅ9네ㅗㅔㄷ8ㅙㄴ트8ㅔㄹㅋ,ㅠㅇ8ㅇㄱㅎㅋ77ㅎㅌ ㄹ룔ㅗ룧

ㅎㅎ초ㅜㅗㅕㅓ랴ㅗㅛ요ㅜㅗ녀으ㅛㅗㅇ

Answered by ravilaccs
0

Answer:

The program is constructed

Explanation:

Problem Statement:

  • There are N players which are playing a tournament. We need to find the maximum number of games the winner can play.
  • In this tournament, two players are allowed to play against each other only if the difference between games played by them is not more than one.

Examples:

Input  : N = 3

Output : 2

Maximum games winner can play = 2

Assume that player are P1, P2 and P3

First, two players will play let (P1, P2)

Now winner will play against P3,

making total games played by winner = 2

Input  : N = 4

Output : 2

Maximum games winner can play = 2

Assume that player are P1, P2, P3 and P4

First two pairs will play lets (P1, P2) and

(P3, P4). Now winner of these two games will

play against each other, making total games

played by winner = 2

  • Approach on {IDE} first, before moving on to the solution.
  • We can solve this problem by first computing the minimum number of players required such that the winner will play x games. Once this is computed actual problem is j the ust inverse of this. Now assume that dp[i] denotes the minimum number of players required so that winner plays i games. We can write a recursive relation among dp values as,  dp[i + 1] = dp[i] + dp[i – 1] because if runner up has played (i – 1) games and the winner has played i games and all players against which they have played the match are disjoint, total games played by the winner will be the addition of those two sets of players.
  • Above recursive relation can be written as dp[i] = dp[i – 1] + dp[i – 2]
  • Which is the same as the Fibonacci series relation, so our final answer will be the index of the maximal Fibonacci number which is less than or equal to the given number of players in the input.

Java program to find maximum number of games played by winner

class Max_game_winner {

// method returns maximum games a winner needs to play in N-player tournament

static int maxGameByWinner(int N)

{

 int[] dp = new int[N];

        // for 0 games, 1 player is needed

 // for 1 game, 2 players are required

 dp[0] = 1;

 dp[1] = 2;

 // loop until i-th Fibonacci number is

 // less than or equal to N

 int i = 2;

 do {

  dp[i] = dp[i - 1] + dp[i - 2];

 } while (dp[i++] <= N);

 // result is (i - 2) because i will be

 // incremented one extra in while loop

 // and we want the last value which is

 // smaller than N, so one more decrement

 return (i - 2);

}

// Driver code to test above methods

public static void main(String args[])

{

 int N = 10;

 System.out.println(maxGameByWinner(N));

}

}

Similar questions