Algorithm
Problem Name: 2 AD-HOC - beecrowd | 1787
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1787
URI
By Jadson José Monteiro Oliveira, Faculdade de Balsas Brazil
Timelimit: 1
Uilton, Rita and Ingred created a new game to decide who will not pay their part of the pizza on next weekend and gave the name "URI" for the game (maybe they decided to join the initials of their names to form the name of the game ). The URI consists of N rounds, each round, each of the three players speak a number, is not allowed equal numbers in a round. If the number that the player to talk is a power of 2, the same earns 1 point, and if in addition to be a power of 2, is the largest number of the round, the player earns 1 more point, if the number is not power of 2 the player does not earn any points. Your task is to create a program that helps to make the account for the score and inform the winner, given the amount of rounds, and the numbers of each round.
Consider that the first 4 powers of 2: 2, 4, 8, 16.
Input
The input contains several test cases. The first line of input contains a single integer N indicating the number of rounds (1 ≤ 10⁵), each of the following N lines contains 3 integers Ui, Ri, Ii (1 <Ui, Ri, Ii ≤ 10⁹), representing respectively the number of Uilton, Rita and Ingred in the i-th round. The end of input is indicated when C = 0.
Output
For each test case output a single line containing the name of the player who has more points. if a draw occurs in the first place, print the name of the game "URI" (without quotes).
Input Sample | Output Sample |
2 2 4 3 2 4 6 2 2 4 6 3 2 16 6 2048 26 7986 2 45 63 69 13 281 4 8 2 6 987 4 39894 7337 1354 0 |
Rita |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
#define ture 1
#define false 0
int main (void)
{
unsigned i;
unsigned numero;
unsigned num[3];
unsigned ui, ri, li;
while (scanf("%u", &numero), numero)
{
ui = ri = li = 0;
while (numero--)
{
int pos = 0;
int maior = 0;
for (i = 0; i < 3; ++i)
{
scanf("%u", &num[i]);
if (num[i] > maior)
maior = num[i], pos = i;
}
if (!(num[0] & (num[0] - 1)))
{
++ui;
if (pos == 0)
++ui;
}
if (!(num[1] & (num[1] - 1)))
{
++ri;
if (pos == 1)
++ri;
}
if (!(num[2] & (num[2] - 1)))
{
++li;
if (pos == 2)
++li;
}
}
if (ui > ri && ui > li)
printf("Uilton\n");
else if (ri > ui && ri > li)
printf("Rita\n");
else if (li > ui && li > ri)
printf("Ingred\n");
else if (li == ui || li == ri || ui == ri)
printf("URI\n");
}
}
Copy The Code &
Try With Live Editor
Input
2 4 3
2 4 6
2 2 4 6
3 2 16
6
2048 26 7986
2 45 63
69 13 281 4 8 2
6 987 4
39894 7337 1354
0
Output
URI
Uilton
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <bits/stdc++.h>
using namespace std;
int potenciade2(int x)
{
if (x == 1) return 1;
else return !(x & (x - 1));
}
int main ()
{
int n;
int u;
int r;
int in;
int su;
int sr;
int sin;
while(1)
{
cin >> n;
if (!n) return 0;
su = sr = sin = 0;
while(n--)
{
cin >> u >> r >> in;
if (potenciade2(u))
{
su++;
if (u == max(max(r,in),u)) su++;
}
if (potenciade2(r))
{
sr++;
if (r == max(max(r,in),u)) sr++;
}
if (potenciade2(in))
{
sin++;
if (in == max(max(r,in),u)) sin++;
}
}
if (su > sr && su > sin) cout << "Uilton\n";
else
{
if (sr > su && sr > sin) cout << "Rita\n";
else
{
if (sin > su && sin > sr) cout << "Ingred\n";
else cout << "URI\n";
}
}
}
}
Copy The Code &
Try With Live Editor
Input
2 4 3
2 4 6
2 2 4 6
3 2 16
6
2048 26 7986
2 45 63
69 13 281 4 8 2
6 987 4
39894 7337 1354
0
Output
URI
Uilton