题目链接: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 ;
}
后续:感谢大牛提出宝贵的意见。。。