Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

HackerEarth The Final Quiz problem solution

YASH PAL, 31 July 2024
In this HackerEarth The Final Quiz problem solution You, Bob, and Alice are playing a quizzing game. Throughout the game, you and the other two competitors have gained some points. Now at the end of the game, the three of you are given a final question. Before you hear the question you have to guess some special points.
If a contestant answers the question correctly he/she will be awarded the points equal to the special points he guessed and the same amount of points (he guessed ) will be deducted in case of a wrong answer. The participant who ends up with the highest score after the final question will end up winning the game.
Now it is time for you to guess your special points. You can bet any amount between 0 and your current score, both inclusive. You are given your current scoreX followed by the current scores of AliceY and BobZ. You are also given special points guessed by Alice A and special points guessed by Bob B. You have to guess your special points, which maximizes your probability of winning the Quiz.
You can assume that you and both the other participants each independently have a 50% chance to answer correctly. If multiple special points can give you the highest probability of winning, choose the minimum one.
HackerEarth The Final Quiz problem solution

HackerEarth The Final Quiz problem solution.

#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--)
{
int a,a1,a2,b1,b2;
cin>>a>>a1>>a2>>b1>>b2;
assert(1<=a&&a<=100000);
assert(1<=a1&&a1<=100000);
assert(1<=a2&&a2<=100000);
assert(0<=b1&&b1<=a1);
assert(0<=b2&&b2<=a2);
int mi=-1;
int ans=1234567;
for(int i=0;i<=a;i++)
{
int x=a-i;
int y=a+i;
int x1=a1-b1;
int x2=a2-b2;
int y1=a1+b1;
int y2=a2+b2;
int c=0;
if(x>x1&&x>x2)
c++;
if(x>x1&&x>y2)
c++;
if(x>y1&&x>x2)
c++;
if(x>y1&&x>y2)
c++;
if(y>x1&&y>x2)
c++;
if(y>x1&&y>y2)
c++;
if(y>y1&&y>x2)
c++;
if(y>y1&&y>y2)
c++;
if(c>mi)
{
mi=c;
ans=i;
}
}
cout<<ans<<"n";
}
return 0;
}
coding problems solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes