SarthakKeshari / CPP-Questions-and-Solutions

This repository aims to solve and create new problems from different spheres of coding. A path to help students to get access to solutions and discuss their doubts.
MIT License
47 stars 132 forks source link

Chef Wars - Return of the Jedi #462

Closed YashGosaliya closed 2 years ago

YashGosaliya commented 2 years ago

Enter your question -

On the ice planet Hoth, Chef has run into his arch-nemesis, DarthForces. Darth has a peculiar fighting style ― he does not attack, but simply defends and lets his opponent tire himself out.

Chef has a lightsaber which has an attack power denoted by P. He keeps hitting Darth with the lightsaber. Every time he hits, Darth's health decreases by the current attack power of the lightsaber (by P points), and afterwards, P decreases to P/2.

If the attack power becomes 0 before Darth's health becomes 0 or less, Chef dies. Otherwise, Darth dies. You are given Darth's initial health H and the initial attack power P. Tell Chef if he can beat Darth or if he should escape.

Input:

--> The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. -->The first and only line of each test case contains two space-separated integers H and P.

Output:

--> For each test case, print a single line containing the integer 1 if Chef can beat Darth or 0 otherwise.

Constraints:

1≤T≤105 1≤P≤105 1≤H≤106

Sample Input: 2 10 4 10 8

Sample Output:

0 1

Explanation

Example case 1: Chef attacks with power 4, Darth's health becomes 6. Chef attacks with power 2, Darth's health becomes 4. Chef attacks with power 1 and Darth's health become 3, but Chef's attack power becomes 0.

Example case 2: Chef attacks with power 8, Darth's health becomes 2. Chef attacks with power 4, Darth's health becomes 0. Chef kills Darth.

Enter link to the question(if question belongs to any online platform) -

https://www.codechef.com/AUG20B/problems/CHEFWARS

Tags for the question(eg - Array, Basic, Stack, etc.) -

CakeWalk, Basic

YashGosaliya commented 2 years ago

Please assign me this issue. @SarthakKeshari

SarthakKeshari commented 2 years ago

@YashGosaliya, Kindly add your solution to "codechef" folder. Deadline - 13/10/2021

This Issue will only be counted towards ranking criteria of this repository.

Gentle advice- A bit more tough questions would be appreciated for Hacktoberfest tag.