Algorithm
Problem Name: beecrowd | 2221
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2221
Pomekons Battle
By Gabriel Duarte, UNIFESO Brazil
Timelimit: 1
After capturing many Pomekons, Dabriel and Guarte resolved to make a battle. The way of the duel is simple, each Master puts a Pomekon in battle and wins who has the Pomekon with the bigger value, which is defined as follows:

The Bonus will be given to the Master Pomekon that are on a level of a value even.
This issue will be given to you the value of the applied bonuses, attack and defense values of Pomekon of Dabriel and Guarte and their levels, you have to inform the winner of the battle.
Input
The entrance is composed of several instances. The first line of input contains an integer T indicating the number of instances. Each instance starts with a integer B (0 ≤ B ≤ 100), which indicates the value of the applied bonus. In the following two lines will have three integers Ai, Di and Li (1 ≤ Ai, Di ≤ 100, 1 ≤ Li ≤ 50), represented the attack value of Pokemon, the defense value and the level of the Master Pomekon. The first line is the Dabriel Pomekon and the second the Guarte.
Output
For each instance in the input you should print the Master's name that will win the battle, in the event of a tie print: "Empate" without quotes.
Input Sample | Output Sample |
3 |
Guarte |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
int main(void)
{
int i, n, a1, a2, d1, d2, b, b1, b2, v1, v2;
scanf("%i", &n);
for (i = 0; i < n; ++i)
{
scanf("%i", &b);
v1=0;
v2=0;
scanf("%i %i %i %i %i %i", &a1, &d1, &b1, &a2, &d2, &b2);
if (b1%2==0)
v1=((a1+d1)/2)+b;
else
v1=(a1+d1)/2;
if (b2%2==0)
v2=((a2+d2)/2)+b;
else
v2=(a2+d2)/2;
if (v1==v2)
printf("Empate\n");
else if (v1 > v2)
printf("Dabriel\n");
else
printf("Guarte\n");
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
#include <ostream>
int main(){
int n, i,winner, bu, atkdefda[5],atkdefgu[5];
std::cin >> n;
for (i = 0;i < n;i++) {
std::cin >> bu;
std::cin >> atkdefda[0] >> atkdefda[1] >> atkdefda[2];
std::cin >> atkdefgu[0] >> atkdefgu[1] >> atkdefgu[2];
//Dabriel
if (atkdefda[2]%2 == 0) {
atkdefda[3] = (atkdefda[0]+atkdefda[1])/2+bu;
}else {
atkdefda[3] = (atkdefda[0]+atkdefda[1])/2;
}
//Guarte
if (atkdefgu[2]%2 == 0) {
atkdefgu[3] = (atkdefgu[0]+atkdefgu[1])/2+bu;
}else {
atkdefgu[3] = (atkdefgu[0]+atkdefgu[1])/2;
}
//winner
if (atkdefda[3] > atkdefgu[3]) {
std::cout << "Dabriel" << std::endl;
} else if (atkdefda[3] == atkdefgu[3]) {
std::cout << "Empate" << std::endl;
} else {
std::cout << "Guarte" << std::endl;
}
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Javascript Programming
Code -
Javascript Programming
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
const values = input.split(/\s+/).map((value) => parseInt(value));
function pomekonsBattle(bonus, player1PokemonsAttack, player2PokemonsAttack) {
const [player1Ai, player1Di, player1Li] = player1PokemonsAttack;
const [player2Ai, player2Di, player2Li] = player2PokemonsAttack;
let player1TotalAttack = (player1Ai + player1Di) / 2.0;
let player2TotalAttack = (player2Ai + player2Di) / 2.0;
if (player1Li % 2 === 0) {
player1TotalAttack += bonus;
}
if (player2Li % 2 === 0) {
player2TotalAttack += bonus;
}
if (player1TotalAttack > player2TotalAttack) {
return "Dabriel";
} else if (player2TotalAttack > player1TotalAttack) {
return "Guarte";
}
return "Empate!";
}
let game = values.shift();
while (game > 0) {
const bonus = values.shift();
const player1PokemonsAttack = values.splice(0, 3);
const player2PokemonsAttack = values.splice(0, 3);
console.log(
pomekonsBattle(bonus, player1PokemonsAttack, player2PokemonsAttack)
);
game--;
}
Copy The Code &
Try With Live Editor
Input
Output
#4 Code Example with Python Programming
Code -
Python Programming
t = int(input())
while t:
t -= 1
b = int(input())
ad, dd, ld = [int(x) for x in input().split()]
ag, dg, lg = [int(x) for x in input().split()]
golped = (ad + dd)/2.0
golpeg = (ag + dg)/2.0
if ld % 2 == 0:
golped += b
if lg % 2 == 0:
golpeg += b
if golped > golpeg:
print('Dabriel')
elif golpeg > golped:
print('Guarte')
else:
print('Empate')
Copy The Code &
Try With Live Editor
Input
Output