Algorithm


Problem Name: beecrowd | 2542

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

Iu-Di-Oh!

 

By Ricardo Oliveira, UFPR BR Brazil

Timelimit: 1

Iu-di-oh! is a card game really popular among kids! Every Iu-di-oh! player has his own deck containing many cards. Each card contains N attributes (such as power, speed, smartness, etc.). Attributes are numbered from 1 to N and are given as positive integers.

A match of Iu-di-oh! is always played by two players. At the beginning of the match, each player chooses exactly one card from his deck. Then, an attribute is randomly chosen. The player whose the chosen attribute is greater in the card he choose wins the match. If the such attribute is equal in both cards, there is a tie.

Marcos and Leonardo are in the big final of the Brazilian Iu-di-oh! championship. The great prize is a Dainavision (that is almost as good as a Plaisteition 2!). Given the deck of both players, the card each one chooses and the chosen attribute, determine the winner!

 

Input

 

The input contains several test cases. The first line of each test case contains an integer N (1 ≤ N ≤ 100), the number of attributes each card contains. The second line contains two integers M and L (1 ≤ M, L ≤ 100), the number of cards in Marcos’ and Leonardo’s deck, respectively.

Next M lines describe Marcos’ deck. His cards are numbered from 1 to M, and i-th line describes the i-th card. Each line contains N integers ai,1,ai,2,..., ai,N (1 ≤ ai,j ≤ 109). Integer ai,j indicates the j-th attribute of the i-th card.

Next L lines describe Leonardo’s deck. His cards are numbered from 1 to L and are described in the same way as Marcos’ deck.

Next line contains two integers CM and CL (1 ≤ CMM, 1 ≤ CLL), the cards chosen by Marcos and Leonardo, respectively. Finally, the last line contains an integer A (1 ≤ AN) indicating the chosen attribute.

The input ends with end-of-file (EOF).

 

Output

 

For each test case, print a line containing “Marcos” if Marcos wins the match, “Leonardo” if Leonardo wins the match, or “Empate” in the case of a tie (without quotes).

 

 

 

Input Sample Output Sample

3
2 2
3 8 1
6 7 9
1 2 3
8 4 1
1 2
2

Marcos

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

int main(void)

{
    int n, m, l, i, j, c1, c2, at, x, y;

    while (scanf("%i %i %i", &n, &m, &l) != EOF)
    {

    int am[m][n], al[l][n];

    for (i = 0; i  <  m; ++i)
    {
        for (j = 0; j  <  n; ++j)
            scanf("%i", &am[i][j]);
    }

    for (i = 0; i  <  l; ++i)
    {
        for (j = 0; j  <  n; ++j)
            scanf("%i", &al[i][j]);
    }

    scanf("%i %i %i", &c1, &c2, &at);

    x=am[c1-1][at-1];
    y=al[c2-1][at-1];

    if (x > y)
        printf("Marcos\n");

    else if (y > x)
        printf("Leonardo\n");

    else
        printf("Empate\n");
    }

    return 0;
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
3 2 2 3 8 1 6 7 9 1 2 3 8 4 1 1 2 2

Output

x
+
cmd
Marcos

#2 Code Example with C++ Programming

Code - C++ Programming


#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int n;
    while(cin >> n)
    {
        int m,l;
        cin >> m >> l;
        vector  < int> M[m];
        vector <int> L[l];
        for(int i = 0; i  <  m; i++)
        {
            for(int j = 0; j  <  n; j++)
            {
                int a;
                cin >> a;
                M[i].push_back(a);
            }
        }
        for(int i = 0; i  <  l; i++)
        {
            for(int j = 0; j  <  n; j++)
            {
                int a;
                cin >> a;
                L[i].push_back(a);
            }
        }
        int MM,LL;cin >> MM >> LL;
        int A;
        cin >> A;
        long long s = M[MM-1][A-1];
        long long S = L[LL-1][A-1];
        if(s>S) cout << "Marcos\n";
        else if(s < S> cout << "Leonardo\n";
        else cout << "Empate\n";
    }
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 2 2 3 8 1 6 7 9 1 2 3 8 4 1 1 2 2

Output

x
+
cmd
Marcos

#3 Code Example with Java Programming

Code - Java Programming


import java.util.Scanner;
import java.io.IOException;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			int n = sc.nextInt(); //numero de atributos de cada carta
			int m = sc.nextInt(); //numero de cartas de Marcos
			int l = sc.nextInt(); //numero de cartas de Leonardo
			
			long[][] cartasM = new long[m][n]; //cartas de Marcos
			//entra cartas de Marcos
			for(int i = 0 ; i  <  m ; i++)
				for(int j = 0 ; j  <  n ; j++)
					cartasM[i][j] = sc.nextLong();
			
			long[][] cartasL = new long[l][n]; //cartas de Leonardo
			//entra cartas de Leonardo
			for(int i = 0 ; i  <  m ; i++)
				for(int j = 0 ; j  <  n ; j++)
					cartasL[i][j] = sc.nextLong();
			
			int cm; //cartas escolhidas por Marcos
			cm = sc.nextInt()-1;
			int cl; //cartas escolidas por Leonardo
			cl = sc.nextInt()-1;
			int a; //atributo sorteado
			a = sc.nextInt()-1;
			
			long Marcos   = cartasM[cm][a];
			long Leonardo = cartasL[cl][a];
			
			if (Marcos > Leonardo)
				System.out.println("Marcos");
			else if (Leonardo > Marcos)
				System.out.println("Leonardo");
			else
				System.out.println("Empate");
		}
		sc.close();
	}
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 2 2 3 8 1 6 7 9 1 2 3 8 4 1 1 2 2

#4 Code Example with Javascript Programming

Code - Javascript Programming


var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
var prompt = function(texto) { return lines.shift();};
while (true) {
  var attck = parseInt(prompt());
  if (isNaN(attck)) {
    break;
  }
  var [cmarcos, cleo] = prompt().split(" ").map(Number);
  var bmarcos = [];
  var bleo = [];

  if (attck == 1) {
    for (let i = 0; i  <  cmarcos; i++) {
      let card = parseInt(prompt());
      bmarcos.push(card);
    }
    for (let i = 0; i  <  cleo; i++) {
      let cartas = parseInt(prompt());
      bleo.push(cartas);
    }
  } else {
    for (let i = 0; i  <  cmarcos; i++) {
      let cartas = prompt().split(" ").map(Number);
      bmarcos.push(cartas);
    }
    for (let i = 0; i  <  cleo; i++) {
      let cartas = prompt().split(" ").map(Number);
      bleo.push(cartas);
    }
  }

  var [marcosescolha, leoescolha] = prompt().split(" ").map(Number);
  var attr = parseInt(prompt());

  if (bmarcos[marcosescolha - 1][attr - 1] > bleo[leoescolha - 1][attr - 1]) {
    console.log("Marcos");
  } else if (
    bmarcos[marcosescolha - 1][attr - 1]  <  bleo[leoescolha - 1][attr - 1]
  ) {
    console.log("Leonardo");
  } else {
    console.log("Empate");
  }
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
3 2 2 3 8 1 6 7 9 1 2 3 8 4 1 1 2 2

#5 Code Example with Python Programming

Code - Python Programming


while True:
    try:
        input()
        e = str(input()).split()
        ncm = int(e[0])
        ncl = int(e[1])
        cm = []
        cl = []
        for i in range(ncm): cm.append([int(x) for x in str(input()).split()])
        for i in range(ncl): cl.append([int(x) for x in str(input()).split()])
        e = str(input()).split()
        ms = int(e[0])
        lu = int(e[1])
        a = int(input())
        if cm[ms-1][a-1] > cl[lu-1][a-1]: print('Marcos')
        elif cm[ms-1][a-1] < cl[lu-1][a-1]: print('Leonardo')
        else: print('Empate')
    except EOFError: break
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 2 2 3 8 1 6 7 9 1 2 3 8 4 1 1 2 2
Advertisements

Demonstration


Previous
#2540 Beecrowd Online Judge Solution 2540 Leader's Impeachment Solution in C, C++, Java, Js and Python
Next
#2543 Beecrowd Online Judge Solution 2543 UFPR Gaming Solution in C, C++, Java, Js and Python