• Codeforces-Div3-E-Rock, Paper, Scissors(贪心)


    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.

    题目大意:两个人玩石头剪刀布,分别给出两个人出石头剪刀布的次数,让你计算其中某一个人能赢的最多次数和最少次数

    思路:类似于田忌赛马

    赢得最多的次数:你出布的时候希望他出石头,以此类推

    赢得最少的次数:需要计算你平局和输的最多的次数,那就是你出布的时候希望他出布或者剪刀,这样就是赢得最少的情况,以此类推

    参考代码

     1 #include <iostream>
     2 using namespace std;
     3 
     4 int main() {
     5     int n;
     6     cin >> n;
     7     int a1, a2, a3, b1, b2, b3;
     8     cin >> a1 >> a2 >> a3 >> b1 >> b2 >> b3;
     9     cout << n - (min(a1, b1 + b3) + min(a2, b2 + b1) + min(a3, b3 + b2)) << " " << min(a1, b2) + min(a2, b3) + min(a3, b1) << endl;
    10     return 0;
    11 }
    View Code
  • 相关阅读:
    转:I3D
    转:显示器接口都有哪些?
    转:斯皮尔曼等级相关系数Spearman's rank correlation coefficient
    转:跳水的动作代码代表什么含义?
    【服务器数据恢复】HP EVA服务器存储RAID信息断电丢失的数据恢复
    【北亚数据恢复】IBM System Storage存储lvm信息丢失数据恢复方案
    【服务器数据恢复】Raid阵列更换故障硬盘后数据同步失败的数据恢复案例
    【虚拟机数据恢复】意外断电导致XenServer虚拟机不可用,虚拟磁盘文件丢失的数据恢复案例
    【数据库数据恢复】SqlServer数据库无法读取的数据恢复案例
    【服务器存储数据恢复】华为OceanStor某型号存储raid5数据恢复案例
  • 原文地址:https://www.cnblogs.com/bianjunting/p/13750652.html
Copyright © 2020-2023  润新知