Archive

Archive for February, 2017

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

February 27th, 2017 2 comments

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 SamplesOutput Samples
1 4 5 0 0Jogador 2 ganha!
1 4 5 1 0Jogador 1 ganha!
1 4 5 1 1Jogador 2 ganha!

 

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

 

solution:

 

[code lang=cpp]
<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;
}

 

[/code]

[URI ONLINE JUDGE] – 2060 – Closing Tabs

February 27th, 2017 No comments

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 SampleOutput 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:

 

#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

February 27th, 2017 No comments

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 SampleOutput Sample
3 5
fechou
fechou
clicou
clicou
clicou
2

 

solution:

 

[code lang=cpp]
<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;
}

 

[/code]

Categories: URI Online Judge Problems Tags:

[URI ONLINE JUDGE] – 2062 – OBI URI

February 27th, 2017 No comments

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 SamplesOutput 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:

 

[code lang=cpp]
<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;
}

 

[/code]

 

[URI ONLINE JUDGE] – 2063 – Hunting Digletts

February 27th, 2017 No comments

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 SamplesOutput Samples
2

2 1

2
4

4 3 2 1

2
6

2 1 5 3 6 4

4

 

solution:

 

[code lang=cpp]
<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;
}

 

[/code]