zoukankan      html  css  js  c++  java
  • Codeforces Round #281 (Div. 2)

    题目链接:http://codeforces.com/contest/493

    A. Vasya and Football

    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.

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

    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

    题意:Vasya作为足球裁判,给犯规球员两种惩罚:一是黄牌,二是红牌。黄牌两次等同于红牌,红牌一次就判下场。现在给出两个队球员的惩罚情况,输出被罚红牌的球员所在的球队、球员编号和被罚下的时间(这些信息在输入中会给出)。

    解法:简单题,直接搞。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstdlib>
     4 #include<cstring>
     5 #include<cmath>
     6 #include<algorithm>
     7 #define inf 0x7fffffff
     8 using namespace std;
     9 const int maxn=111;
    10 int an[2][maxn];
    11 char str[2][22];
    12 int main()
    13 {
    14     int n;
    15     int time,num;
    16     char s[5],s2[5];
    17     memset(str,0,sizeof(str));
    18     while (scanf("%s",str[0])!=EOF)
    19     {
    20         scanf("%s",str[1]);
    21         scanf("%d",&n);
    22         memset(an,0,sizeof(an));
    23         int flag=0;
    24         for (int i=0 ;i<n ;i++)
    25         {
    26             scanf("%d %s %d %s",&time,s,&num,s2);
    27             int t=0;
    28             if (s[0]=='h') t=0;
    29             else t=1;
    30             if (an[t][num]==-1) continue;
    31             if (s2[0]=='y') an[t][num] ++ ;
    32             if ((an[t][num] && an[t][num]%2==0)||(s2[0]=='r'))
    33             {
    34                 printf("%s %d %d
    ",str[t],num,time);
    35                 flag=1;
    36                 an[t][num]=-1;
    37             }
    38         }
    39         if (!flag) printf("
    ");
    40     }
    41     return 0;
    42 }
    View Code

    B. Vasya and Wrestling

    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.

    Input

    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.

    Output

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

    input
    5
    1
    2
    -3
    -4
    3
    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|), 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了三回,第一次数组开小了,第二次脑残给输入的值排了个序,第三次没有注意到值越界。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cstdlib>
     5 #include<cmath>
     6 #include<algorithm>
     7 #define inf 0x7fffffff
     8 using namespace std;
     9 typedef long long ll;
    10 const int maxn=2e5+10;
    11 char str[maxn][12];
    12 char str2[maxn][12];
    13 int cmp_string(const void *_a,const void *_b)
    14 {
    15     char *a=(char *)_a;
    16     char *b=(char *)_b;
    17     return strcmp(a,b)<0;
    18 }
    19 int main()
    20 {
    21     int n;
    22     int num;
    23     char s[12];
    24     while (scanf("%d",&n)!=EOF)
    25     {
    26         memset(str,0,sizeof(str));
    27         memset(str2,0,sizeof(str2));
    28         int c=0,c2=0;
    29         ll total=0,total2=0;
    30         int number=0;
    31         for (int i=0 ;i<n ;i++)
    32         {
    33             scanf("%d",&num);
    34             if (i==n-1) number=num;
    35             memset(s,0,sizeof(s));
    36             if (num>0)
    37             {
    38                 total += (ll)num;
    39                 int cnt=10;
    40                 while (num)
    41                 {
    42                     s[cnt]=(num%10)+'0';
    43                     num /= 10;
    44                     cnt -- ;
    45                 }
    46                 cnt ++ ;
    47                 strcpy(str[c],s+cnt);
    48                 c ++ ;
    49             }
    50             else
    51             {
    52                 num=-num ;total2 += (ll)num ;
    53                 int cnt=10;
    54                 while (num)
    55                 {
    56                     s[cnt]=(num%10)+'0' ;
    57                     num /= 10;
    58                     cnt -- ;
    59                 }
    60                 cnt ++ ;
    61                 strcpy(str2[c2],s+cnt);
    62                 c2 ++ ;
    63             }
    64         }
    65         if (total>total2) {printf("first
    ");continue; }
    66         else if (total<total2) {printf("second
    ");continue; }
    67         else
    68         {
    69             //qsort(str,c,sizeof(str[0]),cmp_string);
    70             //qsort(str2,c2,sizeof(str2[0]),cmp_string);
    71 //            for (int i=0 ;i<c ;i++) cout<<str[i]<<endl;
    72 //            for (int i=0 ;i<c2 ;i++) cout<<str2[i]<<endl;
    73             int flag=0;
    74 
    75             for (int i=0 ;i<c && i<c2 ;i++)
    76             {
    77                 int len=strlen(str[i]);
    78                 int len2=strlen(str2[i]);
    79                 if (len>len2) {flag=1;break; }
    80                 else if (len<len2) {flag=2;break; }
    81                 if (strcmp(str[i],str2[i])>0) {flag=1;break; }
    82                 else if (strcmp(str[i],str2[i])<0) {flag=2;break; }
    83             }
    84             if (flag==1) {printf("first
    ");continue; }
    85             else if (flag==2) {printf("second
    ");continue; }
    86             else
    87             {
    88                 if (c>c2) {printf("first
    ");continue;}
    89                 else if (c<c2) {printf("second
    ");continue; }
    90                 else {
    91                     if (number>0) printf("first
    ");
    92                     else printf("second
    ");
    93                 }
    94             }
    95         }
    96     }
    97     return 0;
    98 }
    View Code

    C. Vasya and Basketball

    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.

    Input

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

    Output

    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.

    input
    3
    1 2 3
    2
    5 6
    output
    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))。

     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdlib>
     4 #include<cstdio>
     5 #include<cmath>
     6 #include<algorithm>
     7 #define inf 0x7fffffff
     8 using namespace std;
     9 const int maxn=2e5+10;
    10 int n,m;
    11 int an[maxn],bn[maxn],cn[maxn*2];
    12 int main()
    13 {
    14     while (scanf("%d",&n)!=EOF)
    15     {
    16         int cnt=0;
    17         cn[cnt++]=0;
    18         for (int i=0 ;i<n ;i++)
    19         {
    20             scanf("%d",&an[i]);
    21             cn[cnt++]=an[i];
    22         }
    23         scanf("%d",&m);
    24         for (int i=0 ;i<m ;i++)
    25         {
    26             scanf("%d",&bn[i]);
    27             cn[cnt++]=bn[i];
    28         }
    29         sort(cn,cn+cnt);
    30         sort(an,an+n);
    31         sort(bn,bn+m);
    32         int ans=-inf,a=0,b=0;
    33         for (int i=0 ;i<cnt ;i++)
    34         {
    35             int total=0,total2=0;
    36             int k=upper_bound(an,an+n,cn[i])-an;
    37             total=2*k+3*(n-k);
    38             int k2=upper_bound(bn,bn+m,cn[i])-bn;
    39             total2=2*k2+3*(m-k2);
    40             if (total-total2>ans)
    41             {
    42                 ans=total-total2;
    43                 a=total ;b=total2 ;
    44             }
    45         }
    46         printf("%d:%d
    ",a,b);
    47     }
    48     return 0;
    49 }
    View Code

    后续:感谢大牛提出宝贵的意见。。。

  • 相关阅读:
    家庭网络拓扑架构
    网络基础概念(IP、MAC、网关、子网掩码)
    centos7搭建docker并部署lnmp (转)
    docker容器里面安装php的redis扩展
    docker 安装ps命令
    Docker Ubuntu容器安装ping
    docker 安装nginx
    CentOS7 安装特定版本的Docker
    docker 卸载旧版本
    Centos7搭建Docker部署LNMP
  • 原文地址:https://www.cnblogs.com/huangxf/p/4142760.html
Copyright © 2011-2022 走看看