Codeforces 493 ABCD

Source: Internet
Author: User
Tags integer numbers

A. Vasya and Football


A. Vasya and Footballtime limit per test:2 secondsmemory limit per test:256 megabytesinput:standard inputoutput:standard o Utput

Vasya had started watching football games. He has learned this for some fouls the players receive yellow cards, and for some fouls, they receive red cards. A player who receives the second yellow card automatically receives a red card.

Vasya is watching a recorded football match now and makes notes of all the fouls so he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time and he would receive a red card from Vasya.

Input

The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines is not empty. The lengths of both lines does not exceed 20. Each line contains only of large 中文版 letters. The names of the teams is distinct.

Next follows number n (1?≤? N? ≤?90)-the number of fouls.

Each of the following n lines contains information on a foul in the following form:

    • First goes number t (1?≤? T ? ≤?90 )-the minute when the foul occurs;
    • then goes letter "h " or letter "a " -if the "h ", then the card were given to a home team player, otherwise th E Card is given to an away team player;
    • then goes the player's number m (1?≤? M ? ≤?99 );
    • then goes letter "y " or letter "r " -if the letter is "y ", which means that the yellow card was given, otherwise the RE D card was given.

The players from different teams can has the the same number. The players within one team has distinct numbers. The fouls go chronologically, no. Fouls happened at the same minute.

Output

For each event if a player received his first red card in a chronological order print a string containing the F Ollowing Information:

    • The name of the team to which the player belongs;
    • The player's number in his team;
    • The minute when he received the card.

If no player received a card, then you does not need to print anything.

It's possible case, the program won't print anything to the output (if there were no red cards).

Sample Test (s) Input
MCCSKA928 a 3 y62 h y66 H y70 H y77 a 4 y79 a y82 H-r89 H y90 A
Output
MC 70MC 82CSKA 13 90

Football matches, the players will be a red card or yellow cards, two yellow cards equal to a red card, the output of the first time the team was a red card situation.
Read test instructions, direct enumeration. It's so simple and rude.

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace Std;struct Node {char team;int y,r;bool vis;} H[101],a[101];int Main () {//freopen ("In.txt", "R", stdin); int N;char home[22],away[22];cin>>home>>away; cin>>n;for (int i=0;i<n;i++) {int T,m;char s[10],c[10];cin>>t>>s>>m>>c;if (s[0]== ') H ') {if (c[0]== ' y ') {h[m]. Y++;if (H[m]. Y% 2 = = 0 && h[m].vis!=true) {h[m]. r++;cout<
B. Vasya and Wrestling

B. Vasya and Wrestlingtime limit per test:2 secondsmemory limit per test:256 megabytesinput:standard Inputoutput:standard Output

Vasya have become interested in wrestling. In wrestling wrestlers with techniques for which they is awarded points by judges. The wrestler who gets the most points wins.

When the numbers of points of both wrestlers was equal, the wrestler whose sequence of points islexicographically Grea Ter, wins.

If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.

Input

The first line contains number n -the number of techniques the wrestlers H Ave Used (1?≤? N ? ≤?2 105 ).

The following n lines contain integer numbersai (| Ai|? ≤?109,ai-≠?0). IfAi am positive, that means then the first wrestler performed the technique that was AWA Rded withai points. And ifai am negative, that means then the second wrestler performed the technique that WA S awarded with(?-? Ai) points.

The techniques is given in chronological order.

Output

If the first wrestler wins, print string "first", otherwise print "second"

Sample Test (s) Input
512-3-43
Output
Second
Input
3-1-23
Output
First
Input
24-4
Output
Second
Note

Sequence x?? =?? x 1x2 ... X| X| Islexicographically largerthan sequence y?? =?? y 1y2 ... Y| Y| , if either| x|?? >??| y|and x1?? =?? y 1,?? x 2?? =?? y 2,?...,?? x | y|?? =?? y | y| , or there is such numberR( r?? <??| x|,? r?? <??| y|), that x1?? =?? y 1,?? x 2?? =?? y 2,?? ... ,?? x r?? =?? y r and xr?? +?? 1?? ?? y r?? +?? 1 .

We Use notation | A| To denote length of sequencea.

Wrestling match, is the first score, negative for the second score. Winner output of the largest total. Score the same as the output score sequence of the dictionary sequence large, the scoring sequence of the same output last score.
Data explosion int.

#include <cstdio> #include <string> #include <cstring> #include <iostream> #include <  Algorithm>using namespace Std;long long N;long long F[200010];long long s[200010];long long _f = 0, _s = 0;string judge (Long Long A) {Long Long _sum_f = 0;long long _sum_s = 0;for (Long long i=0; i<_f; i++) _sum_f + = F[i];for (long long i=0; i<_s; i+ +) _sum_s + = s[i];//cout<< _sum_f << "" << _sum_s <<endl;if (_sum_f > _sum_s) return "first"; F (_sum_f < _sum_s) return "second", if (_sum_f = = _sum_s) {for (long long i=0; i< min (_f, _s); i++) {if (F[i] > S [i]) return "first", if (F[i] < s[i]) return "second";} if (_f > _s) return "first", if (_f < _s) return "second", if (_f = = _s) {if (a > 0) return "first", if (a < 0) r Eturn "Second";}}} int main () {//freopen ("In.txt", "R", stdin), Long long a;cin>>n;for (long long i=0;i<n;i++) {cin>>a;if (a &G T 0) f[_f++] = a;if (A < 0) s[_s++] =-A;} Cout<<judge (a) <&Lt;endl;return 0;} 

C. Vasya and Basketball

C. Vasya and Basketballtime limit per test 2 secondsmemory limit per test megabytesinput standard InputOutput Standard Output

Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful the throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it's made from doesn ' t exceed some value ofD meters, and a throw is W Orth 3 points if the distance is larger thanD meters, whereD is some non-negative integer.

Vasya would like the advantage of the points scored by the first team (the points of the first team minus the points of th E second team) to be maximum. For that he can mentally choose the value ofD. Help him.

Input

The first line contains integer n (1?≤? N? ≤?2 105)-the number of throws of the first team. Then follown integer numbers-the distances of throwsai (1?≤? Ai? ≤?2 109).

Then follows number m (1?≤? M.≤?2 105)-the number of the throws of the second team. Then followm integer numbers-the distances of throws ofbi (1?≤? bi? ≤?2 109).

Output

Print numbers in the format a:b -the score so is possible considering the problem conditions where the R Esult of subtractiona?-? b is maximum. If There is several such scores, find the one in which numbera is maximum.

Sample Test (s) Input
31 2 325 6
Output
9:6
Input
56 7 8 9 1051 2 3 4 5
Output
15:10

Give two teams shooting point and rebound distance, ask to determine the three points line, so that team A as far as possible than B Division, output score ratio, if there are many, output a team the highest situation.
See the topic to think with two minutes, but not thinking, so also did not make out. Later worshipped the code.
Enumerate A team's distance a[K], and take him as a three-point line, in team B to find the smallest greater than a[K] position. Then count the points. and update the results.
Two minutes and write the death setback.
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace STD; #define INF 999999999int a[200010];int b[200010];int _a = 0;int _b = 0;int twofen (int a) {int L = 0, r = _b; int M;WH Ile (l<r) {m = (L + r)/2;cout<<m<< "", if (B[m] >= a) R = m;if (B[m] < a) L = m+1;} return r;} int main () {freopen ("In.txt", "R", stdin), cin>>_a;for (int i=0; i<_a; i++) {cin>>a[i];} cin>>_b;for (int j=0; j<_b; J + +) {cin>>b[j];} Sort (A, a + _a); sort (b, B + _b); A[_a] = B[_b] = Inf;int __a, __b;int ___a = _a * 2, ___b = _b * 2;for (int i=0; i<_a; i++) {__a = i * 2 + (_a-i) * 3;int j = Twofen (A[i]);cout<<j<< ""; __b = J * 2 + (_B-J) *3;if ((__a-_ _b > ___a-___b) | | ((__a-__b = = ___a-___b) && __a > ___a)) {___a = __a;___b = __b;}} printf ("%d:%d\n", ___a,___b); return 0;}

D. Vasya and Chess

D. Vasya and Chesstime limit per test 2 secondsmemory limit per test megabytesinput standard InputOutput standard OUTP Ut

Vasya decided to learn to play chess. Classic chess doesn ' t seem interesting to him, so he plays his own sort of chess.

The Queen is the piece so captures all squares in its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell contains a piece of the Enemy color, the Queen is able to move to this square. After the enemy ' s piece are removed from the board. The Queen cannot move to a cell containing an enemy piece if there are some other piece between it and the Queen.

There is an n? x? N chessboard. We ' ll denote a cell on the intersection of theR-th row andC-th columnas (R,? C). The square(1,?1) contains the White Queen and the square (1,? n) contains the black queen. All the other squares contain green pawns and that's don ' t belong to anyone.

The players move in turns. The player is moves first plays for the White Queen, and his opponent plays for the Black queen.

On each move the player have to capture some piece with he queen (that's, move to a square that contains either a green p Awn or the enemy queen). The player loses if either he cannot capture any piece during his move or the opponent took his queen during the previous Move.

Help Vasya determine who wins if both players play with a optimal strategy on the boardn? x? N.

Input

The input contains a single number n (2?≤? N? ≤?109)-the size of the board.

Output

On the first line print the answer to Problem-string 'white ' or string 'black', depending on who wins If the both players play optimally.

If the answer is 'white ', then you should also print and integersR andC representing the cell ( R,? C), where the first player should make he first move to win. If There is multiple such cells, print the one with the minimum R. If there is still multiple squares, print the one with the minimum C.

Sample Test (s) Input
2
Output
White1 2
Input
3
Output
Black
Note

In the first sample test the White queen can capture the black queen on the first move, so the "the white player wins."

The second test from the statement if the White queen captures the green pawn located on the central vertical Line, the n It'll be captured by the Black Queen during the next move. So the-only move for the white player was to capture the green pawn located at (2,?1).

Similarly, the Black queen doesn ' t has any other options but to capture the green pawn located at(2,?3), Otherwi Se if it goes to the middle vertical line, it'll be a captured by the White Queen.

During the next move the same thing happens-neither the white, nor the Black Queen have other options rather than to Capt Ure Green pawns situated above them. Thus, the White Queen ends up on square(3,?1), and the black Queen ends up on square (3,?3).

In this situation the Queen have to capture all of the green pawns located on the middle vertical 'll is captured by the Black queen. Thus, the player plays for the Black queen wins.


A game problem. Thank you, meow, the great God.

The Black queen and the White Queen are in the squares of n * N, moving in the direction of the vertical and diagonal. Each movement must have eaten a green son, or another queen, eaten or no green son can eat even if lose.

Think about it, if n is odd, then the Black queen can win just by following White Queen's Walk. Because if the White Queen arrives in column (n/2+1), the Black Queen can also reach the same point, and eat it, if the White Queen does not go this column, it can only move between the (1,N/2) column, must be more than the Black queen has no way to go. In conclusion, the White Queen must lose.

If n is an even number, then the White Queen only needs to move to the second column in the first step, so the White Queen moves in the n-1 and the black queen moves first so that it returns to the odd number of cases above. So the White Queen must win.

At this point, the code is out.

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace Std;int Main () {freopen ("In.txt", "R", stdin);    int n;    CIN >> N;    if (n% 2 = = 0) cout << "white\n1 2" << Endl;    else cout << "BLACK" << Endl;    return 0;}

Forge the copper in the next day, dare to call the calf Sun Mountain.




Codeforces 493 ABCD

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.