• CF 1426E


    E. Rock, Paper, Scissors
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Alice and Bob have decided to play the game "Rock, Paper, Scissors".

    The game consists of several rounds, each round is independent of each other. In each round, both players show one of the following things at the same time: rock, paper or scissors. If both players showed the same things then the round outcome is a draw. Otherwise, the following rules applied:

    • if one player showed rock and the other one showed scissors, then the player who showed rock is considered the winner and the other one is considered the loser;
    • if one player showed scissors and the other one showed paper, then the player who showed scissors is considered the winner and the other one is considered the loser;
    • if one player showed paper and the other one showed rock, then the player who showed paper is considered the winner and the other one is considered the loser.

    Alice and Bob decided to play exactly nn rounds of the game described above. Alice decided to show rock a1a1 times, show scissors a2a2 times and show paper a3a3 times. Bob decided to show rock b1b1 times, show scissors b2b2 times and show paper b3b3 times. Though, both Alice and Bob did not choose the sequence in which they show things. It is guaranteed that a1+a2+a3=na1+a2+a3=n and b1+b2+b3=nb1+b2+b3=n.

    Your task is to find two numbers:

    1. the minimum number of round Alice can win;
    2. the maximum number of rounds Alice can win.
    Input

    The first line of the input contains one integer nn (1n1091≤n≤109) — the number of rounds.

    The second line of the input contains three integers a1,a2,a3a1,a2,a3 (0ain0≤ai≤n) — the number of times Alice will show rock, scissors and paper, respectively. It is guaranteed that a1+a2+a3=na1+a2+a3=n.

    The third line of the input contains three integers b1,b2,b3b1,b2,b3 (0bjn0≤bj≤n) — the number of times Bob will show rock, scissors and paper, respectively. It is guaranteed that b1+b2+b3=nb1+b2+b3=n.

    Output

    Print two integers: the minimum and the maximum number of rounds Alice can win.

    Examples
    input
    Copy
    2
    0 1 1
    1 1 0
    
    output
    Copy
    0 1
    
    input
    Copy
    15
    5 5 5
    5 5 5
    
    output
    Copy
    0 15
    
    input
    Copy
    3
    0 0 3
    3 0 0
    
    output
    Copy
    3 3
    
    input
    Copy
    686
    479 178 29
    11 145 530
    
    output
    Copy
    22 334
    
    input
    Copy
    319
    10 53 256
    182 103 34
    
    output
    Copy
    119 226
    
    Note

    In the first example, Alice will not win any rounds if she shows scissors and then paper and Bob shows rock and then scissors. In the best outcome, Alice will win one round if she shows paper and then scissors, and Bob shows rock and then scissors.

    In the second example, Alice will not win any rounds if Bob shows the same things as Alice each round.

    In the third example, Alice always shows paper and Bob always shows rock so Alice will win all three rounds anyway.

    题意:Alice 和Bob玩石头剪刀布,两人都确定下来出的石头剪刀布的个数,问Alice最少赢几句最多赢几句。

    思路:一看就知道是贪心,问题就是怎么贪,显然最多局数就是把能赢的都赢下来。

      最少的话,我一开始的思路是让平局的都先平掉,然后把能输的输掉,但是这样有点问题,第二个版本是按照Bob的大小顺序,尽可能让Alice能赢的平掉, 再能输的输掉,可惜wa7了。  

      最后感觉还是第一种比较对,然后发现只要把第一种略加修改,再平局的时候不去删减Bob的局数就行了,因为有些平局可能因为其他某一个出法太大了而直接用输覆盖掉了而不用平局,所以不去修改Bob的然后就能把Alice赢的可能性降到最小(感觉挺玄学的,有点难讲清楚,需要意会)

    下附代码:

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<algorithm>
     4 #define ll long long
     5 using namespace std;
     6 int main(){
     7     ll n,s1,j1,b1,s2,j2,b2,ss1,jj1,bb1,ss2,jj2,bb2,flag=1;
     8     scanf("%lld",&n);
     9     scanf("%lld%lld%lld",&s1,&j1,&b1);
    10     ss1=s1,jj1=j1,bb1=b1;
    11     scanf("%lld%lld%lld",&s2,&j2,&b2);
    12     ss2=s2,jj2=j2,bb2=b2;
    13     ss1-=ss2,jj1-=jj2,bb1-=bb2;
    14     if (ss1>0) ss1-=bb2;
    15     if (jj1>0) jj1-=ss2;
    16     if (bb1>0) bb1-=jj2;
    17     ss1=max(0ll,ss1);
    18     bb1=max(0ll,bb1);
    19     jj1=max(0ll,jj1);
    20     printf("%lld %lld",min(ss1,jj2)+min(jj1,bb2)+min(bb1,ss2),min(s1,j2)+min(j1,b2)+min(b1,s2));
    21     return 0;
    22 }
    View Code
  • 相关阅读:
    个人理解闭包
    个人理解回调
    在网站中设置一个分享到功能
    在lua中从一个字符串中移除空间源码
    成都实行积分落户
    unity3D客户端框架
    skynet对Windows环境支持的版本:Windows版skynet
    超期羁押
    资料
    媒体电话
  • 原文地址:https://www.cnblogs.com/i-caigou-TT/p/13769742.html
Copyright © 2020-2023  润新知