[URI ONLINE JUDGE] – 2059 – Odd, Even or Cheating

A new game called Odd, Even or Cheating is currently (OEC) is now one of the most popular games in the world. This game was created when some friends had no internet connection, no cellphone, no computer, and pretty much nothing to do. The game is so popular that is going to happen the mundial championship of OEC and each country of the world will choose a representant to compete in this championship.

The game works like this: it’s a two players game, the player 1 chooses between odd or even, then each player chooses a positive integer, if the sum of these number is even and player 1 chose even, then player 1 wins, if the sum is odd and player 2 chose odd, then player 2 wins. If player 1 chooses odd he/she wins when the sum is odd, and player 2 wins when the sum is even. Nothing new, right?

But now there are two more possible moves, player 1 can cheat to make sure that he/she wins independently of the result of the conventional odd or even game, and player 2 can accuse player 1 of cheating. With these additions in the game if player 1 cheats and player 2 accuses him/her of cheating player 2 wins, if player 2 don’t accuse and player 1 is cheating then player 1 wins, if player 2 accuses the cheat, but player 1 is not cheating then player 1 wins, if player 1 isn’t cheating and player 2 doesn’t accuse player 1 then the game will be played as described previously.

You were hired by OECIO (Odd, Even or Cheating International Organization) to develop a program that given an OEC match it determines the winner.

Input

The input consists of one line with 5 integers: p, j1, j2, r, a. ( 0 ≤ p, r, a ≤ 1 e 1 ≤ j1, j2 ≤ 100).

p is the player 1 choice (if p = 1 then player 1 chooses even, if p = 0 then player 1 chooses odd). j1, j2, represents respectively the numbers that player 1 chose and the number that player 2 chose. r represents if player 1 cheated (if r = 1 then player 1 cheated, if r = 0 then he/she did not), a represents if player 2 accused player 1 of cheating (if a = 1 then he/she did, if a = 0 then he/she did not).

Output

Print “Jogador 1 ganha!” if player 1 won or “Jogador 2 ganha!” if player 2 won (no quotation marks).

Input Samples Output Samples
1 4 5 0 0 Jogador 2 ganha!
1 4 5 1 0 Jogador 1 ganha!
1 4 5 1 1 Jogador 2 ganha!

 

It’s very simple. For any question related to this series, please do not hesitate to contact me :)

 

solution:

 

<br /> 

#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
int p, j1, j2, r, a;
cin >> p >> j1 >> j2 >> r >> a;

if(r) {
if(a) printf("Jogador 2 ganha!\n");
else printf("Jogador 1 ganha!\n");
} else {
if(a) printf("Jogador 1 ganha!\n");
else {
int sum = j1 + j2;
int res;
if(sum % 2) res = 0;
else res = 1;

if(res == p) printf("Jogador 1 ganha!\n");
else printf("Jogador 2 ganha!\n");
}
}

return 0;
}

 

[URI ONLINE JUDGE] – 2060 – Closing Tabs

Bino and Cino are close friends. Bino likes to create mathematical challenges to Cino. This time, Bino created a list of numbers and asked to Cino: How many numbers are multiples of 2, 3, 4 and 5?

This challenge looks simple, but when the list contains many numbers, Cino makes some miscalculations. To help Cino, make a program to solve the Bino’s Challenge.

Input

The first line of input consists of an integer N (1 ≤ N ≤1000), representing the amount of numbers in the Bino’s list.

The second line contains N integers Li (1 ≤ Li ≤ 100), representing the numbers of the Bino’s list.

Output

Print the amount of multiples of 2, 3, 4 and 5 in the list. Note the formatting of the output in the output sample, because it must be followed strictly. “Multiplo(s)” means “Multiple(s)” in English, but you must print the message in Portuguese.

Input Sample Output Sample
5
2 5 4 20 10
4 Multiplo(s) de 2
0 Multiplo(s) de 3
2 Multiplo(s) de 4
3 Multiplo(s) de 5

 

solution:

 

<br /> 

#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
int n;
int m2, m3, m4, m5;
m2 = m3 = m4 = m5 = 0;
cin >> n;

for(int i = 0; i < n; i++) {
int l;
cin >> l;

if(l % 2 == 0) m2++;
if(l % 3 == 0) m3++;
if(l % 4 == 0) m4++;
if(l % 5 == 0) m5++;
}
printf("%d Multiplo(s) de 2\n", m2);
printf("%d Multiplo(s) de 3\n", m3);
printf("%d Multiplo(s) de 4\n", m4);
printf("%d Multiplo(s) de 5\n", m5);

return 0;
}

 

[URI ONLINE JUDGE] – 2061 – Closing Tabs

Péricles has an unique interest in history. With his up-to-date internet browser chromed fox, he wandered in the most obscure sites about ancient Greek mythology.

By some type of cosmic irony, Péricles’ browser was infected by a malware with a peculiar characteristic: every time Péricles closed a tab in his browser, another two opened! However, when Péricles clicked one of the ads (all tabs were infested with ads), the tab crashed, and no other tabs were opened.

Your taks is to compute the final number of tabs of Péricles’s browser, knowing the initial number of tabs and the actions taken by Péricles. There are two possible actions: fechou (when Péricles closed a tab) and clicou (when Péricles clicked on an ad).

Input

The input is initiated by a line containing two integer numbers, N e M (0 < N, M < 500), representing the initial number of tabs and the number of actions performed by Péricles. Each subsequent line contains an action (fechou or clicou). Naturally, the current number of tabs is always greater of equal to zero.

Output

The output must consist of a line containing the final number of tabs.

Input Sample Output Sample
3 5
fechou
fechou
clicou
clicou
clicou
2

 

solution:

 

<br /> 

#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
int n, m;
cin >> n >> m;
for(int i = 0; i < m; i++) {
string s;
cin >> s;
if(s == "fechou") n++;
else n--;
}
cout << n << endl;

return 0;
}

 

[URI ONLINE JUDGE] – 2062 – OBI URI

Mariazinha created an exercise for her sisters Paula and Marta: she distributes a text and asks both to correct this text, knowing that only the OBI and URI words may be written incorrectly, and the error can be only in the last letter.

Your task here is automatize this process, creating a program to make the correction of the texts distributed by Mariazinha in order to check the corrections of her sisters without much work.

Note that if “OB” or “UR” were part of a larger word (for example, “OBOS”), it should not be altered.

Input

The input contains two lines. The first line contain a integer number N (1 < N < 10000) that indicates the amount of text words. The second line contains these text words, each one with up to 20 characters (‘A’-‘Z’), inclusive, or at least, one letter (‘A’-‘Z’).

The input contains several test cases. Each test case is composed by one line that contais a string sentence. This string will contain between 1 and 50 characters (‘A’-‘Z’,’a’-‘z’ or space ‘ ‘), inclusive, or at least, one letter (‘A’-‘Z’,’a’-‘z’).

Output

Your program must correct the text distributed by Mariazinha, according to the criteria above defined.

Input Samples Output Samples
2
OBO URU
OBI URI
3
EURO AVOID OBITS
EURO AVOID OBITS
10
URA URO URI URU UROS IBO OBA OBAS OBES OBE
URI URI URI URI UROS IBO OBI OBAS OBES OBI

 

solution:

 

<br /> 

#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
int n;
cin >> n;
for(int i = 0; i < n; i++) {
string s;
cin >> s;
if(i != 0) printf(" ");
if(s.size() == 3 and s[0] == 'O' and s[1] == 'B') {
printf("OBI");
} else {
if(s.size() == 3 and s[0] == 'U' and s[1] == 'R') {
printf("URI");
} else {
cout << s;
}
}
}
cout << endl;

return 0;
}

 

 

[URI ONLINE JUDGE] – 2063 – Hunting Digletts

Diglett is a Pokémon type of land that is digging underground tunnels and is almost never seen. It appears on the surface through a hole in the ground time to time, where you can view only his head.

Digglets

The tunnels built by them are unidirectional and always connect an origin hole to a destination hole, for example: if there is a tunnel connecting the hole A to the hole B, then it is possible to go from A to B and not the opposite. Each Diglett has its own hole, which indicates that there N holes will be N Digletts. Each hole has exactly two tunnels: the first tunnel, which runs from it to another hole and the second tunnel, which comes to him from another hole.

The Digletts are walking from hole to hole every moment of time, for example: consider a hole A that has a tunnel that connects to a hole B, if one Diglett in the hole A at time T, then the next moment of time T+1 it will be in the hole B. When a Diglett arrives at his hole, it appears immediately on the surface. When not in his hole, it just remains underground and waiting for the next moment of time to walk the tunnel and go to another hole. It is guaranteed that each Diglett always returns to its hole in a moment of time.

Xisto is a Pokémom Master and is looking to capture the greatest amount of Digletts with only a pokeball, this in turn is able to capture all visible Digletts in a given area. He needs your help to know what is the shortest time in which all Digletts will appear on the surface at the same time, so he could throw the pokeball and catch them all.

Note: At time zero Digletts are all in their respective hole and does not appear on the surface.

Input

The first row contains an integer N (2 ≤ N ≤ 100) representing the amount of holes. The next line contains N integers Bi (1 ≤ Bi ≤ N), where the i-th integer representing the i-th hole, and indicates a unidirectional tunnel i-th hole to Bi hole.

Output

Print the shortest time in which all Digletts will appear together on the surface.

Input Samples Output Samples
2

2 1

2
4

4 3 2 1

2
6

2 1 5 3 6 4

4

 

solution:

 

<br /> 

#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
int n;
int G[105];

int res = 1;
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> G[i];
}

for(int i = 1; i <= n; i++) {
int p = G[i];
int t = 1;
while(p != i) {
t++;
p = G[p];
}
res = (res/__gcd(res, t)) * t;
}
cout << res << endl;

return 0;
}

 

 

[URI ONLINE JUDGE] – 2065 – Supermarket Line

Today is the inauguration of a huge supermarket in your town, and everyone are excited about the low prices promised.

This supermarket has N cashiers, identified by numbers from 1 to N, where each cashier takes a specific amount of time vi to process an item from a client. Therefore, if a client has cj items on his basket, a specific cashier will take vi*cj seconds to process all of the items from this client.

When a client enters the line to be attended he waits until a cashier is free. If more than one cashier are free at the same time, he will be attended by the cashier with the lowest identification number. This cashier will only be free again when he finishes processing all of the clients items.

There are M clients on the line to be attended, each with a specific number of items on his basket. Given the information about the cashiers and the clients, the manager asked your help to find out how long it will take so all the clients are attended.

Input

The first line of input has two integers N and M, indicating the number of cashiers and clients, respectively (1 ≤ NM ≤ 104).

Following there will be N integers vi, indicating how long the i-th cashier takes to process an item (1 ≤ vi ≤ 100, for every 1 ≤ iN).

Following there will be M integers cj, indicating how many items the j-th client has (1 ≤ cj ≤ 100, for every 1 ≤ jM).

Output

Print a line containing an integer, indicating how long it will take so all the clients are attended.

Input Samples Output Samples
1 1
3
6
18
1 2
1
5 3
8
2 3
1 2
10 5 3
13

 

solution:

 

<br /> 

#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
int n, m;
int v[10005];
cin >> n >> m;
for(int i = 1; i <=n; i++) {
cin >> v[i];
}

int ans = 0;
priority_queue< pair<int,int> > fila;
for(int i = 1; i <= n; i++) {
fila.push( make_pair(0, -i) );
}
while(m--) {
int c;
cin >> c;
int id = -fila.top().second;
int l = -fila.top().first;
fila.pop();

fila.push(make_pair(-(l+v[id] * c), -id));
ans = max(ans, l+v[id] * c);
}

printf("%d\n", ans);

return 0;
}

 

 

[URI ONLINE JUDGE] – 2067 – The Square Game

The “square game” is a very popular game nowadays! The game is very simple: you are given a grid with N lines and M columns containing non-negative integer numbers. The following image shows a grid with 3 lines and 4 columns.

You are also given an integer S. You must then choose some square with S lines and S columns contained entirely in the grid. Your score is given by the product of all integers inside the square you chose. For example, if S=2 and you decided to choose the square shown in blue in the given image, your score will be equal to 2×3×2×1 = 12.

You just realized that, depending on the square you choose, your score may be equal to zero. You are given a grid and a list of queries. For each query, you are given an integer S and must decide whether it is possible to choose a SxS square such that your score is not equal to zero.

Input

The first line contains two integers N and M (1 ≤ N, M ≤ 200) indicating the number of lines and columns of the grid. The next N lines contain M integers each, indicating the grid. Each integer in the grid is not greater than 109.

The next line contains an integer Q (1 ≤ Q ≤ 200) indicating the number of queries. Each of the next Q lines describes a query. Each line contains an integer S (1 ≤ S ≤ min(N,M)), the length of the square you must choose.

Output

For each query, print a single line containing yes if it is possible to choose a square such that your score is not equal to zero, or no otherwise.

Input Sample Output Sample
3 4
3 4 0 3
0 2 3 1
4 2 1 0
3
2
3
1
yes
no
yes

 

solution:

 

<br /> 

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{

int n, m, q;
int grid[205][205];
int dp[205][205];
int maior = 0;
memset(dp, 0, sizeof dp);

cin >> n >> m;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
cin >> grid[i][j];
if(grid[i][j] == 0) {
dp[i][j] = 0;
} else {
dp[i][j] = min(dp[i-1][j-1],
min(dp[i-1][j], dp[i][j-1])) + 1;
maior = max(maior, dp[i][j]);
}
}
}

cin >> q;
while(q--) {
int t;
cin >> t;
if(t <= maior) printf("yes\n");
else printf("no\n");
}

return 0;
}