Algorithm


Problem Name: beecrowd | 2709

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

The Coins of Robbie

 

By Adriano Pereira Almeida, Centro Universitário Estácio da Amazônia BR Brazil

Timelimit: 1

Robbie is a robot very charismatic, and one of things that he most like to do, besides playing with Glória, it's collect coins. Robbie has several coins with equal or different values, and the same size. They’re stored in na organize manner on top of each other, inside a glass cylinder. Robbie Always do a little game with Glória using his coins when she ask to play with him from hide and seek, or when she asks him to take her for a walk. The rule of the game is: Glória have to choose any number N, which will be added, then for each coin N the value of the coin Vi is added until there aren’t no more coins, in other words Ʃ of ((VM-(N*0) )+(VM-(N*1))+(VM-(N*2))...), M it’s the number of coins. For exemple, if there’re 5 coins with values 1, 2, 3, 4 and 5, and Glória choose 2 as a number of jump, them the coins will be added 5, 3 and 1, result in 9. In the end, Robbie checks if the sum of these coins is a prime number, if this happen, he do what Glória want, if doesn’t happen, the little girl convince Robbie to play again, Cause she Always convince him to do everything, saying that will stop to tell him stories, if he doesn’t make her wish.

You as a good developer of U.S Robots, will help this two friends, writting a computer program that will say the result of the game.

 

Input

 

The input contains several test cases. The first line of a test case contains an integer M (2 ≤ M ≤ 20) that represents the quantity of coins. Each of the next lines M contains an integer Vi (1 ≤ Vi ≤500) that represents the value of coins Mi , and for the last one, a integer N (1 ≤ N ≤ M) that’s the jump in the added choosen by Gloria.

The input ends with EOF.

 

Output

 

Print “You’re a coastal aircraft, Robbie, a large silver aircraft.”, if Gloria win the game, or “Bad boy! I’ll hit you.”, if Glória loose the game. The output should be no quotation marks.

 

 

 

Input Sample Output Sample

5
1
2
3
4
5
2

5
1
2
3
4
5
3

Bad boy! I’ll hit you.

You’re a coastal aircraft, Robbie, a large silver aircraft.

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define true 1
#define false 0
#define WIN "You’re a coastal aircraft, Robbie, a large silver aircraft."
#define LOSE "Bad boy! I’ll hit you."

_Bool is_prime(unsigned);

int main(int argc, char **argv)
{

	int vet[30];
	int n, i, s, ans;

	while (scanf("%d", &n) != EOF)
	{

		for (i = 0; i  <  n; ++i)
			scanf("%d", &vet[i]);

		scanf("%d", &s);

		ans = 0;
		i = n - 1;
		while (i >= 0)
			ans += vet[i], i -= s;

		printf("%s\n", is_prime(ans) ? WIN : LOSE);

	}

	return 0;

}

_Bool is_prime(unsigned num)
{

	unsigned i;
	unsigned raiz = (int)sqrt(num);

	if (num != 2  && num % 2 == 0 || num == 1)
		return false;

	for (i = 3; i  < = raiz; i += 2)
		if (num % i == 0)
			return false;

	return true;

}
Copy The Code & Try With Live Editor

Input

x
+
cmd
5 1 2 3 4 5 2 5 1 2 3 4 5 3

Output

x
+
cmd
Bad boy! I’ll hit you. You’re a coastal aircraft, Robbie, a large silver aircraft.

#2 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>
#include <cmath>

using namespace std;

bool eprimo(short *n) {
  short i, lim = sqrt(*n);
  if (*n != 2 && *n%2 == 0 || *n == 1) return false;
  for (i = 3; i  < = lim; i += 2)
    if (*n%i == 0) return false;
  return true;
}

int main(void) {
  short m, n, s, i;
  short v[20];

  while (cin >> m) {
    s = 0;
    for (i = 0; i  <  m; ++i)
      cin >> v[i];
    cin >> n;
    --i;
    while (0  < = i) {
      s += v[i];
      i -= n;
    }
    if (eprimo(&s))
      cout << "You’re a coastal aircraft, Robbie, a large silver aircraft.";
    else cout << "Bad boy! I’ll hit you.";
    cout << endl;
  }

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

Input

x
+
cmd
5 1 2 3 4 5 2 5 1 2 3 4 5 3

Output

x
+
cmd
Bad boy! I’ll hit you. You’re a coastal aircraft, Robbie, a large silver aircraft.

#3 Code Example with Java Programming

Code - Java Programming


import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.useLocale(Locale.ENGLISH);
		Locale.setDefault(new Locale("en", "US"));
		
		while(sc.hasNext()) {
			int m = sc.nextInt(); //quantidade de moedas
			List < Integer> v = new ArrayList();
			for(int x = 0 ; x  <  m ; x++)
				 v.add(sc.nextInt()); //valor da moeda
			
			int n=sc.nextInt(); //salto das moedas que serao somadas
			int soma=0;
			
			Collections.reverse(v);

			for (int i = 0 ; i  <  v.size() ; i+=n)
				soma+=v.get(i);
			
			if(soma!=1 && soma!=0 && ehprimo(soma))
				System.out.println("You�re a coastal aircraft, Robbie, a large silver aircraft.");
			else
				System.out.println("Bad boy! I�ll hit you.");
		}
		sc.close();
	}

	private static boolean ehprimo(int soma) {
	    for (int j = 2; j < soma; j++) {
	        if (soma % j == 0>
	            return false;   
	    }
	    return true;
	}
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
5 1 2 3 4 5 2 5 1 2 3 4 5 3

Output

x
+
cmd
Bad boy! I’ll hit you. You’re a coastal aircraft, Robbie, a large silver aircraft.
Advertisements

Demonstration


Previous
#2708 Beecrowd Online Judge Solution 2708 Tourists in the Huacachina Park Solution in C, C++, Java, Js and Python
Next
#2712 Beecrowd Online Judge Solution 2712 Vehicular Restriction Solution in C, C++, Java, Js and Python