Codeforces Round #281 (Div. 2) A,B,C,D

来源:互联网 发布:知乎 描写河流 编辑:程序博客网 时间:2024/06/05 22:30
A. Vasya and Football
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

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

  • first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs;
  • then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was 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", that means that the yellow card was given, otherwise the red card was given.

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.

Output

For each event when a player received his first red card in a chronological order print a string containing the following 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 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).

Examples
Input
MCCSKA928 a 3 y62 h 25 y66 h 42 y70 h 25 y77 a 4 y79 a 25 y82 h 42 r89 h 16 y90 a 13 r
Output
MC 25 70MC 42 82CSKA 13 90
题意:输入2支球队名字,有9名队员犯规,h表示第一支队伍中的队员,a表示第二支队伍中的队员,每名球员输入犯规的时间,哪支队伍,多少号,犯的red或者yellow牌,2张yellow牌相当于一张red牌,按时间顺序求出所有球员犯红牌的时间,哪支球队,多少号。
思路:按时间排序,直接模拟即可。可以struct 也可以pair套pair。
#include<cstdio>#include<cstdlib>#include<iostream>#include<stack>#include<queue>#include<algorithm>#include<cstring>#include<cmath>#include<vector>#include<map>#include<set>#define mem(a,b) memset(a,b,sizeof(a))#define memmax(a) memset(a,0x3f,sizeof(a))#define pfn printf("\n")#define ll __int64#define mod 1000000007#define sf(a) scanf("%d",&a)#define sf64(a) scanf("%I64d",&a)#define sf264(a,b) scanf("%I64d%I64d",&a,&b)#define sf364(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)#define sf2(a,b) scanf("%d%d",&a,&b)#define sf3(a,b,c) scanf("%d%d%d",&a,&b,&c)#define sf4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)#define sff(a) scanf("%f",&a)#define sfs(a) scanf("%s",a)#define sfs2(a,b) scanf("%s%s",a,b)#define sfs3(a,b,c) scanf("%s%s%s",a,b,c)#define sfc(a) scanf("%c",&a)#define debug printf("***\n")const double PI = acos(-1.0);const double e = exp(1.0);const int INF = 0x7fffffff;;template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }template<class T> inline T Min(T a, T b) { return a < b ? a : b; }template<class T> inline T Max(T a, T b) { return a > b ? a : b; }bool cmpbig(int a, int b){ return a>b; }bool cmpsmall(int a, int b){ return a<b; }using namespace std;struct arnode{int time;int flag;int num;int foul;};bool cmp(arnode a, arnode b){return a.time < b.time;}typedef pair<int, int>P;int main(){//freopen("data.in", "r", stdin);char n1[22], n2[22];while (~sfs(n1)){arnode node[100];sfs(n2);int n,i;int a1[100], b1[100];mem(a1, 0); mem(b1, 0);sf(n);for (i = 0; i < n; i++){sf(node[i].time);char c;getchar();sfc(c);c == 'a' ? node[i].flag = 2 : node[i].flag = 1;sf(node[i].num);//printf("%c %d\n",c, node[i].num);getchar();sfc(c);c == 'r' ? node[i].foul = 2 : node[i].foul = 1;}int vis1[100],vis2[100];mem(vis1, 0);mem(vis2, 0);for (i = 0; i < n; i++){if (node[i].flag == 1){if (node[i].foul == 1)a1[node[i].num]++;elsea1[node[i].num] += 2;if (a1[node[i].num] >= 2 && !vis1[node[i].num]){printf("%s %d %d\n", n1, node[i].num, node[i].time);vis1[node[i].num] = 1;}}else{if (node[i].foul == 1)b1[node[i].num]++;elseb1[node[i].num] += 2;if (b1[node[i].num] >= 2 && !vis2[node[i].num]){printf("%s %d %d\n", n2, node[i].num, node[i].time);vis2[node[i].num] = 1;}}}}
<span class="kwd">return</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span>
<span class="pun"></span><span class="pln"></span><span class="pun">}</span>
Output
second
Input
3-1-23
Output
first
Input
24-4
Output
second
Note

Sequence x  =  x1x2...x|x| islexicographically 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 andxr  +  1  >  yr  +  1.

We use notation |a| to denote length of sequencea.

题意:有n次摔跤动作,正数表示first得分,负数绝对值表示second得分,得分高的赢,如果得分相同,则字典序大的赢,如果字典序相同,则最后表演完动作的赢。

思路:sum来判断是否相等,sum>0则first win,sum<0则second win,然后用两个数组保存值,判断字典序即可。

#include<cstdio>#include<cstdlib>#include<iostream>#include<stack>#include<queue>#include<algorithm>#include<cstring>#include<cmath>#include<vector>#include<map>#include<set>#define mem(a,b) memset(a,b,sizeof(a))#define memmax(a) memset(a,0x3f,sizeof(a))#define pfn printf("\n")#define ll __int64#define mod 1000000007#define sf(a) scanf("%d",&a)#define sf64(a) scanf("%I64d",&a)#define sf264(a,b) scanf("%I64d%I64d",&a,&b)#define sf364(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)#define sf2(a,b) scanf("%d%d",&a,&b)#define sf3(a,b,c) scanf("%d%d%d",&a,&b,&c)#define sf4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)#define sff(a) scanf("%f",&a)#define sfs(a) scanf("%s",a)#define sfs2(a,b) scanf("%s%s",a,b)#define sfs3(a,b,c) scanf("%s%s%s",a,b,c)#define sfc(a) scanf("%c",&a)#define debug printf("***\n")const double PI = acos(-1.0);const double e = exp(1.0);const int INF = 0x7fffffff;;template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }template<class T> inline T Min(T a, T b) { return a < b ? a : b; }template<class T> inline T Max(T a, T b) { return a > b ? a : b; }bool cmpbig(int a, int b){ return a>b; }bool cmpsmall(int a, int b){ return a<b; }using namespace std;typedef pair<int, int>P;#define MAX 2000010ll a[MAX];ll b[MAX];int judge(int cnt1, int cnt2){int i, j;for (i = 0, j = 0; i < cnt1, j < cnt2; i++, j++){if (a[i]>b[j])return 1;if (a[i] < b[j])return 2;}if (i == cnt1&&j != cnt2) return 1;if (i != cnt1&&j == cnt2) return 2;if (i == cnt1&&j == cnt2) return 0;}int main(){//freopen("data.in", "r", stdin);ll n;while (~sf64(n)){ll i,cnt1=0,cnt2=0,pos;ll sum = 0;for (i = 0; i < n; i++){sf64(pos);pos>0 ?a[cnt1++]=pos : b[cnt2++]=abs(pos);sum += pos;}if (sum!=0){sum>0? printf("first\n") : printf("second\n");continue;}if (judge(cnt1, cnt2) == 1) printf("first\n");if (judge(cnt1, cnt2) == 2)printf("second\n");if (judge(cnt1, cnt2) == 0)pos > 0 ? printf("first\n") : printf("second\n");}return 0;}

C. Vasya and Basketball
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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, whered 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.

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 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.

Examples
Input
31 2 325 6
Output
9:6
Input
56 7 8 9 1051 2 3 4 5
Output
15:10
题意:有2个人进行投篮比赛,第一个投n次,第二个投m次,每次投篮距离ai,小于d距离得2分,大于等于则得3分,求出最大的第一个人得分减去第二个人得分的差值,如果有多个相同的,则输出第一个人得分最高的那组。
思路:枚举下能投篮的位置,当然不是0~2*10^9这样枚举,这样肯定超时,将n+m 这些距离枚举,再枚举2个临界值0和2*10^9,然后二分找到这些值在n 和m中的位置,算出得分即可,当然也可以直接用lower_bound更简便(本鶸表示想练练二分写法- -)还有一点要注意的是距离差是可以为负的,初始化时记得赋-INF(这里被坑成sb,wa了4发才发现自己的错误。。。
#include<cstdio>#include<cstdlib>#include<iostream>#include<stack>#include<queue>#include<algorithm>#include<cstring>#include<cmath>#include<vector>#include<map>#include<set>#define mem(a,b) memset(a,b,sizeof(a))#define memmax(a) memset(a,0x3f,sizeof(a))#define pfn printf("\n")#define ll __int64#define mod 1000000007#define sf(a) scanf("%d",&a)#define sf64(a) scanf("%I64d",&a)#define sf264(a,b) scanf("%I64d%I64d",&a,&b)#define sf364(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)#define sf2(a,b) scanf("%d%d",&a,&b)#define sf3(a,b,c) scanf("%d%d%d",&a,&b,&c)#define sf4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)#define sff(a) scanf("%f",&a)#define sfs(a) scanf("%s",a)#define sfs2(a,b) scanf("%s%s",a,b)#define sfs3(a,b,c) scanf("%s%s%s",a,b,c)#define sfc(a) scanf("%c",&a)#define debug printf("***\n")const double PI = acos(-1.0);const double e = exp(1.0);const int INF = 0x7fffffff;;template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }template<class T> inline T Min(T a, T b) { return a < b ? a : b; }template<class T> inline T Max(T a, T b) { return a > b ? a : b; }bool cmpbig(int a, int b){ return a>b; }bool cmpsmall(int a, int b){ return a<b; }using namespace std;typedef pair<int, int>P;#define MAX 2000010int a[MAX];int b[MAX];int vis[MAX * 2];int main(){//freopen("data.in", "r", stdin);int n;while (~sf(n)){int i, m;vis[0] = 0;for (i = 0; i < n; i++){sf(a[i]);vis[i + 1] = a[i];}sf(m);for (i = 0; i < m; i++){sf(b[i]);vis[i + n + 1] = b[i];}vis[n + m + 1] = 2 * pow(10, 9);sort(a, a + n);sort(b, b + m);sort(vis, vis + n + m + 2);int pos1,pos2;ll sum1 = 0,cnt1=0, sum2 = 0,cnt2=0;ll dis = -INF;for (i = 0; i < n+m+2; i++){cnt1 = 0; cnt2 = 0;int left=0, right=m-1, mid;while (left < right){mid = (left + right) >> 1;if (b[mid] < vis[i])left = mid + 1;elseright = mid;}if (left == m - 1)vis[i]>b[m - 1]?pos2 = m:pos2 = m - 1;elsepos2 = left;left = 0, right = n - 1;while (left < right){mid = (left + right) >> 1;if (a[mid] < vis[i])left = mid + 1;elseright = mid;}if (left == n - 1)vis[i]>a[n - 1] ? pos1 = n : pos1 = n - 1;elsepos1 = left;cnt1 = pos1 * 2 + (n - pos1) * 3;cnt2 = pos2 * 2 + (m - pos2) * 3;if (dis <= cnt1 - cnt2){if (dis == cnt1 - cnt2)sum1 = max(sum1, cnt1), sum2 = max(sum2, cnt2);else{sum1 = cnt1; sum2 = cnt2;dis = cnt1 - cnt2;}}}printf("%I64d:%I64d\n", sum1, sum2);}return 0;}

D. Vasya and Chess
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 the r-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 board n × 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 two integers r 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 minimum r. If there are still multiple squares, print the one with the minimum c.

Examples
Input
2
Output
white1 2
Input
3
Output
black
题意:n*n的格子,player1操作白色queue在1,1位置,player2操作黑色queue在1,n位置,queue每次能走一格八个方向,走过的不能走,也可以吃掉对方的queue,谁被吃或者谁没路走就输了。
思路:这题就像象棋中翻翻棋的逼近法,自己在纸上画一画就能发现,如果行为奇数则player1肯定被逼死,反之player2被逼死,发现这样 ,即可立刻A掉此题。
#include<cstdio>#include<cstdlib>#include<iostream>#include<stack>#include<queue>#include<algorithm>#include<cstring>#include<cmath>#include<vector>#include<map>#include<set>#define mem(a,b) memset(a,b,sizeof(a))#define memmax(a) memset(a,0x3f,sizeof(a))#define pfn printf("\n")#define ll __int64#define mod 1000000007#define sf(a) scanf("%d",&a)#define sf64(a) scanf("%I64d",&a)#define sf264(a,b) scanf("%I64d%I64d",&a,&b)#define sf364(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)#define sf2(a,b) scanf("%d%d",&a,&b)#define sf3(a,b,c) scanf("%d%d%d",&a,&b,&c)#define sf4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)#define sff(a) scanf("%f",&a)#define sfs(a) scanf("%s",a)#define sfs2(a,b) scanf("%s%s",a,b)#define sfs3(a,b,c) scanf("%s%s%s",a,b,c)#define sfc(a) scanf("%c",&a)#define debug printf("***\n")const double PI = acos(-1.0);const double e = exp(1.0);const int INF = 0x7fffffff;;template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }template<class T> inline T Min(T a, T b) { return a < b ? a : b; }template<class T> inline T Max(T a, T b) { return a > b ? a : b; }bool cmpbig(int a, int b){ return a>b; }bool cmpsmall(int a, int b){ return a<b; }using namespace std;typedef pair<int, int>P;int main(){//freopen("data.in", "r", stdin);int n;while (~sf(n)){if (n & 1)printf("black\n");elseprintf("white\n1 2\n");}return 0;}

0 0