Heaps: Gladiator Strength In a fighting tournament, every gladiator fights with another gladiator, and every gladiator h

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Heaps: Gladiator Strength In a fighting tournament, every gladiator fights with another gladiator, and every gladiator h

Post by answerhappygod »

Heaps Gladiator Strength In A Fighting Tournament Every Gladiator Fights With Another Gladiator And Every Gladiator H 1
Heaps Gladiator Strength In A Fighting Tournament Every Gladiator Fights With Another Gladiator And Every Gladiator H 1 (68.76 KiB) Viewed 56 times
Heaps Gladiator Strength In A Fighting Tournament Every Gladiator Fights With Another Gladiator And Every Gladiator H 2
Heaps Gladiator Strength In A Fighting Tournament Every Gladiator Fights With Another Gladiator And Every Gladiator H 2 (62.08 KiB) Viewed 56 times
Heaps Gladiator Strength In A Fighting Tournament Every Gladiator Fights With Another Gladiator And Every Gladiator H 3
Heaps Gladiator Strength In A Fighting Tournament Every Gladiator Fights With Another Gladiator And Every Gladiator H 3 (54.27 KiB) Viewed 56 times
Heaps: Gladiator Strength In a fighting tournament, every gladiator fights with another gladiator, and every gladiator has a specified strength. When two gladiators with strengths a & b fight (a <= b), there are 2 possibilities: 1. If a = b, both are eliminated. 2. Else a is eliminated and strength of b is reduced to b-a. In every fight, two gladiators with maximum strength clash. After all the rounds, only one gladiator wins. Find minimum strength that the winning gladiator can have. Print 0 if no gladiator is left after the final fight. Function Description In the provided code snippet, implement the provided lastGladiatorStrength (...) method using the variables to print the minimum final strength of the winning gladiator. You can write your code in the space below the phrase "WRITE YOUR LOGIC HERE". There will be multiple test cases running so the Input and Output should match exactly as provided. The base Output variable result is set to a default value of -404 which can be modified. Additionally, you can add or remove these output variables. Input Format The first line contains an integer N denoting the total number of gladiators. The second line contains N space-separated integers A a... an-1-
Sample Input 5 29418 -- denotes the total number of gladiators N denotes the strengths of N gladiators Constraints 1 <= N <= 30 1 <= Ai <= 1000. Output Format The output contains an integer denoting the minimum strength that the winning gladiator can have. If no gladiator is left, print 0. Sample Output 0 Explanation 1st fight is between gladiators with strengths 9 & 8. After the fight, the gladiator with strength 8 is eliminated and the opponent's strength is reduced to 1. The array becomes [2,1,4,1,0]. 2nd fight is between gladiators with strengths 4 & 2. After the fight, the gladiator with strength 2 is eliminated and the opponent's strength is reduced to 2. The array becomes [0,1,2,1,0]. 3rd fight is between gladiators with strengths 2 & 1. After the fight, the gladiator with strength 1 is eliminated and the opponent's strength is reduced to 1. The array becomes [0,0,1,1,0]. 4th fight, which is the last fight, is between gladiators with strengths 1 & 1. Both are eliminated. The array becomes [0,0,0,0,0]. Since there are no gladiators left, the output is 0.
1 import java.util.*; 2 import java.io.*; 3 import java.lang.Math; 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 public class Main{ public static int lastGladiatorStrength(int n, int[] A) { //this is default OUTPUT. You can change it. int result = -404; //write your Logic here: } } return result; public static void main (String[] args) { Scanner sc = new Scanner(System.in); // INPUT [uncomment & modify if required] int N = sc.nextInt (); int[] A = new int [N]; for (int i = 0; i < N; i++) { A = sc.nextInt (); } } sc.close(); System.out.print(lastGladiatorStrength (N, A));
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply