Algorithm


Problem Name: 2 AD-HOC - beecrowd | 1627

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1627

Last Hit

 

By Cristhian Bonilha, UTFPR BR Brazil

Timelimit: 1

Andre and Beto are playing a computer game that rewards the players in a very particular way: only the one that gives the last hit to defeat a monster will get all the gold that the monster leave behind. This implies that, although others players may have helped to defeat the monster, only the one who gives the last hit will be rewarded.

Andre is intrigued with this system, and asked your help. Given the number of life points of the monster, the damage that Andre and Beto can cause, and the lead time necessary between two consecutive attacks, find out who will give the last hit on the monster, defeating it and getting the reward.

At the beginning both Andre and Beto will attack, dealing At and Bt damage points, respectively. After each attack, both Andre and Beto have to wait exactly Ad and Bd seconds, respectively, before they can attack again. Whenever Andre and Beto can attack at the same time (as in the beginning), Andre has the priority and attacks first. A monster is defeated when its life points come to less or equal to zero.

 

Input

 

The first line contains an integer T, indicating the number of test cases to follow.

Each test case starts with four integers At, Ad, Bt and Bd (1 ≤ At, Ad, Bt, Bd ≤ 100), indicating the attack damage and the lead time between two consecutive attacks of Andre and Beto, respectively.

Following there will be an integer H (1 ≤ H ≤ 10000), indicating the number of life points of the monster.

 

Output

 

For each test case print one line containing one name, this being “Andre” if he's the last one to hit the monster, or “Beto” otherwise.

 

 

 

Sample Input Sample Output

3
5 3 5 3
10
5 3 5 3
11
5 3 10 7
213

Beto
Andre
Andre

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int t, at, ad, bt, bd, h, ra, rb;

	cin >> t;

	while(t--)
	{
		 cin >> at >> ad >> bt >> bd ;
		 cin >> h ;
		ra = rb = 0;

		while(true)
		{
			if(ra <= rb){
				h -= at;
				rb -= ra;
				ra = ad;

				if(h  < = 0){
					printf("Andre\n");
					break;
				}
			}else{
				h -= bt;
				ra -= rb;
				rb = bd;

				if(h  < = 0){
					printf("Beto\n">;
					break;
				}
			}
		}
	}

	return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
5 3 5 3
10
5 3 5 3
11
5 3 10 7
213

Output

x
+
cmd
Beto
Andre
Andre

#2 Code Example with Python Programming

Code - Python Programming


for _ in range(int(input())):
    at,ad,bt,bd=map(int,input().split())
    h=int(input())
    ra=rb=0
    while True:
        if ra<=rb:
            h-=at
            rb-=ra
            ra=ad
            if h<=0:print('Andre');break
        else:
            h-=bt
            ra-=rb
            rb=bd
            if h < =0:print('Beto');break
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
5 3 5 3
10
5 3 5 3
11
5 3 10 7
213

Output

x
+
cmd
Beto
Andre
Andre
Advertisements

Demonstration


Previous
#1619 Beecrowd Online Judge Solution 1619 Date Difference Solution in C, C++, Java, Js and Python
Next
#1639 Beecrowd Online Judge Solution 1639 Generate Random Numbers Solution in C, C++, Java, Js and Python