codeforces 493 ABCD

A. Vasya and Football

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

Sample test(s)

Input

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

Output

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;
}

B. Vasya and Wrestling

B. Vasya and Wrestling

time limit per test:2 seconds

memory limit per test:256 megabytes

input:standard input

output:standard output

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.

Input

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.

Output

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

Sample test(s)

Input

5
1
2
-3
-4
3

Output

second

Input

3
-1
-2
3

Output

first

Input

2
4
-4

Output

second

Note

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.

摔跤比赛,正的为 first 得分,负的为 second 得分。求 winner 输出总分最大的。总分相同输出得分序列字典序大的,得分序列相同输出最后一个得分的.

数据爆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";
	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;
}

C. Vasya and Basketball

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

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.

Sample test(s)

Input

3
1 2 3
2
5 6

Output

9:6

Input

5
6 7 8 9 10
5
1 2 3 4 5

Output

15:10

给出俩个队伍投篮点与篮板的距离,要求确定三分线,使得 A 队尽可能的比B队分多,输出得分比,如果有多种,输出 A 队分最高的情况。

看到题目想到用二分算,但没想通思路,所以也没做出来。后来膜拜代码。

枚举 A 队的距离 a[ k ] ,并以他为三分线,在 B 队里面找最小的大于 a[ k ] 的位置。然后算分。并更新结果。

二分又写的死挫死挫。

#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;
}

D. Vasya and Chess

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

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

Sample test(s)

Input

2

Output

white
1 2

Input

3

Output

black

Note

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;
}

打铁铸铜来年日,敢叫牛犊不孙山。

时间: 2024-10-07 15:44:53

codeforces 493 ABCD的相关文章

codeforces #270 ABCD

Codeforces Round #270 A - Design Tutorial: Learn from Math 题意:给出n,求出两个合数x和y使x+y=n. 题解:暴力筛合数,然后暴力找 1 //#pragma comment(linker, "/STACK:102400000,102400000") 2 #include<cstdio> 3 #include<cmath> 4 #include<iostream> 5 #include<

codeforces 493 C Vasya and Basketball

题意:给出三分线的值d,分别有两支队伍,如果小于等于d,得2分,如果大于d,得三分,问使得a-b最大时的a,b 一看到题目,就想当然的去二分了----啥都没分出来---55555555 后来才知道不能二分,因为随着d的增大,两个队的得分都会逐渐减少,但是两个队伍的得分的差值的单调性却不知道 是这一篇这样讲的 http://www.cnblogs.com/huangxf/p/4142760.html 然后就依次枚举d的值,维护一个最大值 1 #include<iostream> 2 #inclu

codeforces 493 D Vasya and Chess【 博弈 】

题意:给出n*n的棋盘,白方在(1,1),黑方在(1,n)处,每一步可以上下左右对角线走,哪个先抓到另一个,则它获胜 可以画一下,发现n是奇数的时候,白方先走,无论它怎么走,黑方和它走对称的,黑方都一定能赢 n是偶数的时候,将白方走到(1,2)就变成奇数的情况,白方必胜 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<st

codeforces 493 div1 e

题解: 和这件zhcs的那题有点像 第一种做法是考虑i,i+1之间的贡献 这样就是矩形加然后求矩形和 方法1:树套树 方法2:同下面讲的历史版本线段树 另一种做法是我们从左向右维护mx-nx-r+l 跟之前那题一样我们知道这个的最小值为0 另外我们只需要从右向左维护一个单调队列,这样区间取min/max 就可以变成分段区间+/-操作了 然后这样就变成区间+/-然后查询历史为0的个数 这是jry的论文套路 我们对每个节点再维护一个之前考虑的时间 原文地址:https://www.cnblogs.c

codeforces #584 ABCD

A. Paint the Numbers Description Solution 水题 B. Koala and Lights Description Solution 模拟到1e4. C. Paint the Digits Description 给出一个序列,将序列每个值染色为1或2. 问能否给出一种染色序列使得12序列为排序后的序列. Solution 原序列排一遍序比较. 扫两遍,第一次染色1,第二次染色2. 判断染色序列是否完整覆盖原序列. 1 #include <algorithm

Codeforces Round #493 (Div. 2) ABCD

A. Balloons There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens. Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought nn packet

Codeforces Round #258 (Div. 2)[ABCD]

Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意: Akshat and Malvika两人玩一个游戏,横竖n,m根木棒排成#型,每次取走一个交点,交点相关的横竖两条木棒要去掉,Akshat先手,给出n,m问谁赢. 分析: 水题,很明显不管拿掉哪个点剩下的都是(n-1,m-1),最后状态是(0,x)或(x,0),也就是拿了min(n,m)-1次,

Codeforces Round #354 (Div. 2) ABCD

Codeforces Round #354 (Div. 2) Problems # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393 D T

Codeforces Round #250 (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory limit per test:256 megabytes Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between th