Algorithm


Problem Name: 2 AD-HOC - beecrowd | 1419

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

Bakugan

 

By Ines Kereki Uruguay

Timelimit: 1

Mark and Leti love to play with Bakugan balls. These balls are small plastic spheres with a tiny monster toy inside. When dropped to the ground, a Bakugan ball pops open with an incredible sound, liberating a fearsome Bakugan monster. Mark and Leti love to play with the toy monsters, but popping open the balls is also great fun.

Each of them received a bag with Bakugan balls, and they invented a game to pop open the balls. There are 10 different monsters, and for the game Mark and Leti associated each monster with a different integer from 1 to 10, according to the monster’s ugliness. The game is composed of R rounds. At each round:

  • Both players drop simultaneously a ball each;
  • Each player accumulates a number of points coincident with the number associated with the monster liberated by her/his ball;
  • The first (and only the first) player who liberates the same monster in three consecutive rounds earns 30 additional points; if this condition happens in the same round for both players then nobody earns extra points.

The winner of the game is the player who accumulates more points. Please help Mark and Leti announce the winner of the game!

 

Input

 

Each test case is described using three lines. The first line contains an integer R representing the number of rounds of the game (1 ≤ R ≤ 10). The second line contains R integers Mi indicating the monsters liberated by Mark at each turn (1 ≤ Mi ≤ 10 for 1 ≤ iR). The third line contains R integers Li indicating the monsters liberated by Leti at each turn (1 ≤ Li ≤ 10, for 1 ≤ iR).

The last test case is followed by a line containing one zero.

 

Output

 

For each test case output a line with a character representing the result of the game: "M" (uppercase) if the winner is Mark, "L" (uppercase) if the winner is Leti, or "T" (uppercase) if there is a tie.

 

 

 

Sample Input Sample Output

10
4 2 2 2 5 6 7 8 1 1
1 4 4 4 1 1 1 1 2 3
5
3 3 3 3 2
8 9 9 9 9
10
8 4 7 1 1 9 5 2 4 3
5 6 9 7 9 4 2 3 7 4
0

M
T
L

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i  < = b; ++i)
#define RFOR(i, b, a) for (int i = b; i >= a; --i)
#define REP(i, N) for (int i = 0; i  <  N; ++i)
#define MAX 110
#define pb push_back
#define mp make_pair

using namespace std;

const double pi = acos(-1.0);
const double EPS = 1e-9;
const double INF = 1e50;

typedef long long ll;
typedef pair < double, double> dd;

int main()
{
    ios::sync_with_stdio(false);
    int a, b;
    while (cin >> a && a) {
        int M[a], L[a], sM = 0, sL = 0, summomM = 0, summomL = 0;
        bool d = false;
        REP(i, a)
        {
            cin >> M[i];
            sM += M[i];
        }
        REP(i, a)
        {
            cin >> L[i];
            sL += L[i];
        }
        for (int i = 1; i  <  a; ++i) {
            if (!d) {
                if (M[i - 1] == M[i])
                    summomM++;
                else
                    summomM = 0;
                if (L[i - 1] == L[i])
                    summomL++;
                else
                    summomL = 0;
                if (summomM == 2 && summomM != summomL) {
                    sM += 30;
                    d = true;
                } else if (summomL == 2 && summomM != summomL) {
                    sL += 30;
                    d = true;
                }
                if (summomM == summomL && summomL == 2)
                    d = true;
            }
        }
        if (sL == sM)
            cout << "T\n";
        else if (sL > sM)
            cout << "L\n";
        else
            cout << "M\n";
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
10
4 2 2 2 5 6 7 8 1 1
1 4 4 4 1 1 1 1 2 3
5
3 3 3 3 2
8 9 9 9 9
10
8 4 7 1 1 9 5 2 4 3
5 6 9 7 9 4 2 3 7 4
0

Output

x
+
cmd
M
T
L
Advertisements

Demonstration


Previous
#1418 Beecrowd Online Judge Solution 1418 Another Crisis Solution in C, C++, Java, Js and Python
Next
#1421 Beecrowd Online Judge Solution 1421 Tic-Tac-Toe? Solution in C, C++, Java, Js and Python