Codeforces Round #281 (Div. 2)
题目链接:http://codeforces.com/contest/493
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 firstmoment 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:
- 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.
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).
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
题意:Vasya作为足球裁判,给犯规球员两种惩罚:一是黄牌,二是红牌。黄牌两次等同于红牌,红牌一次就判下场。现在给出两个队球员的惩罚情况,输出被罚红牌的球员所在的球队、球员编号和被罚下的时间(这些信息在输入中会给出)。
解法:简单题,直接搞。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int maxn=;
int an[][maxn];
char str[][];
int main()
{
int n;
int time,num;
char s[],s2[];
memset(str,,sizeof(str));
while (scanf("%s",str[])!=EOF)
{
scanf("%s",str[]);
scanf("%d",&n);
memset(an,,sizeof(an));
int flag=;
for (int i= ;i<n ;i++)
{
scanf("%d %s %d %s",&time,s,&num,s2);
int t=;
if (s[]=='h') t=;
else t=;
if (an[t][num]==-) continue;
if (s2[]=='y') an[t][num] ++ ;
if ((an[t][num] && an[t][num]%==)||(s2[]=='r'))
{
printf("%s %d %d\n",str[t],num,time);
flag=;
an[t][num]=-;
}
}
if (!flag) printf("\n");
}
return ;
}
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 is lexicographically 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·10^5).
The following n lines contain integer numbers ai (|ai| ≤ 10^9, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai 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
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|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1.
We use notation |a| to denote length of sequence a.
题意:理解为现有两个人first和second,然后给出一系列的值,值为正则赋值给first,值为负则把它的绝对值赋给second,然后进行判断:
1:如果first和second得到的值不相等,则输出得到值多的那个人。
2:如果值相等,这时候就比较输入中这些值的大小,一旦出现不相等的值,输出值大的那一方。
3:如果还有相等的情况,输出等到最后一个值的那一个人。
解法:感觉解法都在题意里了,挺简单的。我SB了三回,第一次数组开小了,第二次脑残给输入的值排了个序,第三次没有注意到值越界。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
typedef long long ll;
const int maxn=2e5+;
char str[maxn][];
char str2[maxn][];
int cmp_string(const void *_a,const void *_b)
{
char *a=(char *)_a;
char *b=(char *)_b;
return strcmp(a,b)<;
}
int main()
{
int n;
int num;
char s[];
while (scanf("%d",&n)!=EOF)
{
memset(str,,sizeof(str));
memset(str2,,sizeof(str2));
int c=,c2=;
ll total=,total2=;
int number=;
for (int i= ;i<n ;i++)
{
scanf("%d",&num);
if (i==n-) number=num;
memset(s,,sizeof(s));
if (num>)
{
total += (ll)num;
int cnt=;
while (num)
{
s[cnt]=(num%)+'';
num /= ;
cnt -- ;
}
cnt ++ ;
strcpy(str[c],s+cnt);
c ++ ;
}
else
{
num=-num ;total2 += (ll)num ;
int cnt=;
while (num)
{
s[cnt]=(num%)+'' ;
num /= ;
cnt -- ;
}
cnt ++ ;
strcpy(str2[c2],s+cnt);
c2 ++ ;
}
}
if (total>total2) {printf("first\n");continue; }
else if (total<total2) {printf("second\n");continue; }
else
{
//qsort(str,c,sizeof(str[0]),cmp_string);
//qsort(str2,c2,sizeof(str2[0]),cmp_string);
// for (int i=0 ;i<c ;i++) cout<<str[i]<<endl;
// for (int i=0 ;i<c2 ;i++) cout<<str2[i]<<endl;
int flag=; for (int i= ;i<c && i<c2 ;i++)
{
int len=strlen(str[i]);
int len2=strlen(str2[i]);
if (len>len2) {flag=;break; }
else if (len<len2) {flag=;break; }
if (strcmp(str[i],str2[i])>) {flag=;break; }
else if (strcmp(str[i],str2[i])<) {flag=;break; }
}
if (flag==) {printf("first\n");continue; }
else if (flag==) {printf("second\n");continue; }
else
{
if (c>c2) {printf("first\n");continue;}
else if (c<c2) {printf("second\n");continue; }
else {
if (number>) printf("first\n");
else printf("second\n");
}
}
}
}
return ;
}
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 of d meters, and a throw is worth 3 points if the distance is larger than d meters, where d 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 the second team) to be maximum. For that he can mentally choose the value of d. Help him to do that.
The first line contains integer n (1 ≤ n ≤ 2·10^5) — the number of throws of the first team. Then follow n integer numbers — the distances of throws ai (1 ≤ ai ≤ 2·10^9).
Then follows number m (1 ≤ m ≤ 2·10^5) — the number of the throws of the second team. Then follow m integer numbers — the distances of throws of bi (1 ≤ bi ≤ 2·10^9).
Print two numbers in the format a:b — the score that is possible considering the problem conditions where the result of subtraction a - bis maximum. If there are several such scores, find the one in which number a is maximum.
3
1 2 3
2
5 6
9:6
题意:篮球比赛,投篮,有一个三分线d(d>=0),在没有超过距离d的情况下投篮命中得2分,超过d命中得3分。给出两个队各自进球个数和距篮筐的距离,求三分线d,使得第一队总得分减去第二队总得分的差值最大。
解法:题目一读完也许很多人脑中出现了常用的解法思想,比如二分、三分什么的。其实不然,显然,分别对于第一队和第二队,随着d的增大,两个队的总得分都会减少,也就是说针对单独的一个队是符合单调性的,但两个队的差值却无从考证,因为这和输入值有关。所以,二分的思想不能解决此题。
对于此题,我们假设一个数列:1,4,9,10。那么,我们d的取值在[4,8]的时候,对于原数列的影响是一样的(想想?)
所以这时候我们可以把两个队的所有得分时的距离合在一起放在CNi(i=0,,,n+m)数组里,枚举这个数组就ok了,然后再分别求出两个队针对此时d的各自得分,求差值,取最大值(如果有多个最大值,取第一个队得分最大的)。时间复杂度为O((n+m)log(n+m))。
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int maxn=2e5+;
int n,m;
int an[maxn],bn[maxn],cn[maxn*];
int main()
{
while (scanf("%d",&n)!=EOF)
{
int cnt=;
cn[cnt++]=;
for (int i= ;i<n ;i++)
{
scanf("%d",&an[i]);
cn[cnt++]=an[i];
}
scanf("%d",&m);
for (int i= ;i<m ;i++)
{
scanf("%d",&bn[i]);
cn[cnt++]=bn[i];
}
sort(cn,cn+cnt);
sort(an,an+n);
sort(bn,bn+m);
int ans=-inf,a=,b=;
for (int i= ;i<cnt ;i++)
{
int total=,total2=;
int k=upper_bound(an,an+n,cn[i])-an;
total=*k+*(n-k);
int k2=upper_bound(bn,bn+m,cn[i])-bn;
total2=*k2+*(m-k2);
if (total-total2>ans)
{
ans=total-total2;
a=total ;b=total2 ;
}
}
printf("%d:%d\n",a,b);
}
return ;
}
后续:感谢大牛提出宝贵的意见。。。
Codeforces Round #281 (Div. 2)的更多相关文章
- Codeforces Round #281 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/493 A题 写完后就交了,然后WA了,又读了一遍题,没找出错误后就开始搞B题了,后来回头重做的时候才发现,球员被红牌罚下场后还可 ...
- Codeforces Round #281 (Div. 2) D(简单博弈)
题目:http://codeforces.com/problemset/problem/493/D 题意:一个n*n的地图,有两个人在比赛,第一个人是白皇后开始在(1,1)位置,第二个人是黑皇后开始在 ...
- Codeforces Round #281 (Div. 2) B. Vasya and Wrestling 水题
B. Vasya and Wrestling 题目连接: http://codeforces.com/contest/493/problem/B Description Vasya has becom ...
- Codeforces Round #281 (Div. 2) A. Vasya and Football 模拟
A. Vasya and Football 题目连接: http://codeforces.com/contest/493/problem/A Description Vasya has starte ...
- Codeforces Round #281 (Div. 2) D. Vasya and Chess 水
D. Vasya and Chess time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #281 (Div. 2) C. Vasya and Basketball 二分
C. Vasya and Basketball time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces Round #281 (Div. 2) D. Vasya and Chess 镜面对称 博弈论
D. Vasya and Chess time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #281 (Div. 2) C. Vasya and Basketball 暴力水题
C. Vasya and Basketball time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces Round #281 (Div. 2) A. Vasya and Football 暴力水题
A. Vasya and Football time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
随机推荐
- Cassandra 技术选型的问题
Cassandra在国内资料少,用的也不多,大家更多抱观望态度吧. 为了扩大Cassandra队伍帮助自己采坑,决定写一篇文章,就自己对Cassandra的理解范围进行介绍. 选用Cassandra的 ...
- ThinkPHP之中的getField、Find、select、返回数据类型详解(ThinkPHP之中所有数据读取了)
小李子:用于演示作用的数据库表:customers 官方解读: “ 读取数据集其实就是获取数据表中的多行记录(以及关联数据),使用select方法 ” $customers=D('customers' ...
- 【转】在delphi中实现控件的拖拽
提示:可以添加一个布尔来控制可否拖动的状态,这里提供所有都能拖动的方法. procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseB ...
- 共享内存 share pool (2):BUCKET /FREE LISTS /RESERVED FREE LISTS /UNPINNED RECREATABLE CHUNKS (lru first)
相关概念 BUCKET :每个bucket上挂有一个 chunk list.同一个BUCKET中的chunk在物理地址上是不一定相邻的 FREE LISTS:按bucket划分,共有255个,buck ...
- [terry笔记]Flashback
flashback 闪回,主要功能有两个:闪回查询(flashback query).闪回恢复(flashback table/database) 开启闪回flashback功能(归档下才可开启数据库 ...
- 几条sql语句
1.行.列转换 --行转列 ),科目 ),分数 int) ) ) ) ) ) ) ) ) ) --方法1 select 姓名, end) as 语文, end) as 数学, end) as 物理 f ...
- 在Ubuntu下设置环境变量
在Ubuntu中有如下几个文件可以设置环境变量 /etc/profile:在登录时,操作系统定制用户环境时使用的第一个文件,此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行. /e ...
- ruby cookbook
11.2 listing object's method Oject.methods/singleton_methods/instance_methods 指定类名定义的方法在 singleton_m ...
- JTable的DefaultModel方法getValueAt(a,row)
行和列都是从0开始索引的,而且不包括netbeans生成的表格头,而是从数据开始,否则就会报错
- lnmp的使用
命令 1.状态管理 lnmp {start|stop|reload|restart|kill|status} 2.添加虚拟host lnmp vhost add