Chef Wars – Return of the Jedi Codechef Solution

Chef Wars – Return of the Jedi Codechef Solution: 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 PP. He keeps hitting Darth with the lightsaber. Every time he hits, Darth’s health decreases by the current attack power of the lightsaber (by PP points), and afterwards, PP decreases to ⌊P2⌋⌊P2⌋.

If the attack power becomes 00 before Darth’s health becomes 00 or less, Chef dies. Otherwise, Darth dies. You are given Darth’s initial health HH and the initial attack power PP. Tell Chef if he can beat Darth or if he should escape.

Input

  • The first line of the input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
  • The first and only line of each test case contains two space-separated integers HH and PP.

Output

For each test case, print a single line containing the integer 11 if Chef can beat Darth or 00 otherwise.

Constraints

  • 1≤T≤1051≤T≤105
  • 1≤P≤1051≤P≤105
  • 1≤H≤1061≤H≤106

Sample Input 1 

2
10 4
10 8

Sample Output 1 

0
1

Explanation

Example case 1: Chef attacks with power 44, Darth’s health becomes 66. Chef attacks with power 22, Darth’s health becomes 44. Chef attacks with power 11 and Darth’s health becomes 33, but Chef’s attack power becomes 00.

Example case 2: Chef attacks with power 88, Darth’s health becomes 22. Chef attacks with power 44, Darth’s health becomes 00. Chef kills Darth.

Chef Wars – Return of the Jedi  – CodeChef Solution in JAVA

import java.util.*;
import java.io.*;
class Codechef {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for (int tt=0; tt<t; tt++) {
            int h = sc.nextInt();
            int p = sc.nextInt();
            if ((h-p) >= p) {
                System.out.println(0);
            } else {
                System.out.println(1);
            }
        }
    }
}

Chef Wars – Return of the Jedi – CodeChef Solution in CPP

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
       int a,b;
       cin>>a>>b;
       while(a!=0 &&  b!=0){
           a=a-b;
           b=b/2;
           if(a<=0){
           cout<<1<<endl;
           break;
       }
       else if(b==0) {cout<<0<<endl;break;}
       }
   }
}

Chef Wars – Return of the Jedi-CodeChef Solution in Python

for t in range(int(input())):
    h,p=map(int,input().split())
    while True:
        h=h-p
        if h<=0:
            print(1)
            break
        else:
            p=p//2
            if p==1 and (h-p)>0:
                print(0)
                break

Disclaimer: The above Problem (Chef Wars – Return of the Jedi ) is generated by CodeChef but the solution is provided by  Chase2learn.This tutorial is only for Educational and Learning purpose.

Leave a Comment