标签:codeforces
Vasya has started watching football games. He has learned that 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 that 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 when he would receive a red card from Vasya.
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 are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct.
Next follows number n (1?≤?n?≤?90) — the number of fouls.
Each of the following n lines contains information about a foul in the following form:
The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute.
For each event when a player received his first red card in a chronological order print a string containing the following information:
If no player received a card, then you do not need to print anything.
It is possible case that the program will not print anything to the output (if there were no red cards).
MC CSKA 9 28 a 3 y 62 h 25 y 66 h 42 y 70 h 25 y 77 a 4 y 79 a 25 y 82 h 42 r 89 h 16 y 90 a 13 r
MC 25 70 MC 42 82 CSKA 13 90
#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<<home<<" "<<m<<" "<<t<<endl; h[m].vis=true; } } if (c[0]=='r' && h[m].vis!=true) { h[m].R++; cout<<home<<" "<<m<<" "<<t<<endl; h[m].vis=true; } } if (s[0]=='a') { if (c[0]=='y') { a[m].Y++; if (a[m].Y % 2 == 0 && a[m].vis!=true) { a[m].R++; cout<<away<<" "<<m<<" "<<t<<endl; a[m].vis=true; } } if (c[0]=='r' && a[m].vis!=true) { a[m].R++; cout<<away<<" "<<m<<" "<<t<<endl; a[m].vis=true; } } } return 0; }
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points islexicographically greater, 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.
The first line contains number n — the number of techniques that the wrestlers have used (1?≤?n?≤?2·105).
The following n lines contain integer numbersai (|ai|?≤?109,ai?≠?0). Ifai is positive, that means that the first wrestler performed the technique that was awarded withai points. And ifai is negative, that means that the second wrestler performed the technique that was awarded with(?-?ai) points.
The techniques are given in chronological order.
If the first wrestler wins, print string "first", otherwise print "second"
5 1 2 -3 -4 3
second
3 -1 -2 3
first
2 4 -4
second
Sequence x??=??x1x2...x|x| is lexicographically larger than sequence y??=??y1y2...y|y|, if either |x|??>??|y| and x1??=??y1,??x2??=??y2,?... ,??x|y|??=??y|y|, or there is such number r (r??<??|x|,?r??<??|y|), thatx1??=??y1,??x2??=??y2,??... ,??xr??=??yr and xr??+??1??>??yr??+??1.
We use notation |a| to denote length of sequencea.
#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"; if (_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) return "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 > 0) f[_f++] = a; if (a < 0) s[_s++] = -a; } cout<<judge(a)<<endl; return 0; }
Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn‘t exceed some value ofd meters, and a throw is worth 3 points if the distance is larger thand meters, where d is somenon-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 the second team) to be maximum. For that he can mentally choose the value ofd. Help him to do that.
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).
Print two numbers in the format a:b — the score that is possible considering the problem conditions where the result of subtractiona?-?b is maximum. If there are several such scores, find the one in which numbera is maximum.
3 1 2 3 2 5 6
9:6
5 6 7 8 9 10 5 1 2 3 4 5
15:10
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define INF 999999999 int a[200010]; int b[200010]; int _a = 0; int _b = 0; int twofen (int A) { int l = 0, r = _b ; int m; while (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; }
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 that captures all squares on 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 that the enemy‘s piece is removed from the board. The queen cannot move to a cell containing an enemy piece if there is some other piece between it and the queen.
There is an n?×?n chessboard. We‘ll denote a cell on the intersection of ther-th row and c-th column as(r,?c). The square (1,?1) contains the white queen and the square (1,?n) contains the black queen. All other squares contain green pawns that don‘t belong to anyone.
The players move in turns. The player that moves first plays for the white queen, his opponent plays for the black queen.
On each move the player has to capture some piece with his queen (that is, move to a square that contains either a green pawn 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 an optimal strategy on the boardn?×?n.
The input contains a single number n (2?≤?n?≤?109) — the size of the board.
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 two integersr and c representing the cell(r,?c), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimumr. If there are still multiple squares, print the one with the minimumc.
2
white 1 2
3
black
In the first sample test the white queen can capture the black queen at the first move, so the white player wins.
In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for the white player is to capture the green pawn located at (2,?1).
Similarly, the black queen doesn‘t have any other options but to capture the green pawn located at(2,?3), otherwise if it goes to the middle vertical line, it will be captured by the white queen.
During the next move the same thing happens — neither the white, nor the black queen has other options rather than to capture 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 white queen has to capture any of the green pawns located on the middle vertical line, after that it will be captured by the black queen. Thus, the player who plays for the black queen wins.
一道博弈题。感谢喵呜大神。
在 n * n 的格子里有黑皇后和白皇后,移动方向为横竖和对角线。每个移动都必须有吃到一颗绿子,或者另一个皇后,被吃掉或者没有绿子可吃就算输。
想想看,如果n是奇数,那么黑皇后只要跟着白皇后的走法走就可以赢。因为白皇后如果到了第 (n/2+1) 列,黑皇后也可以到达相同点,并把它吃掉,如果白皇后不走这列,则只能在(1,n/2)列之间移动,一定比黑皇后先无路可走。综上,白皇后一定输。
如果 n 是偶数,那么白皇后只需要第一步移动到第二列,这样,白黑皇后在 n-1 列格子里移动,并且黑皇后先移动,这样就回到了上面奇数的情况了。所以白皇后一定赢。
至此,代码就出来了。
#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; }
标签:codeforces
原文地址:http://blog.csdn.net/xuelanghu407/article/details/41879861