【Codeforces 1426 E】Rock, Paper, Scissors,贪心!算反面

举报
小哈里 发表于 2022/05/11 00:50:23 2022/05/11
【摘要】 problem E. Rock, Paper, Scissors time limit per test1 second memory limit per test256 megabytes input...

problem

E. Rock, Paper, Scissors
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 n rounds of the game described above. Alice decided to show rock a1 times, show scissors a2 times and show paper a3 times. Bob decided to show rock b1 times, show scissors b2 times and show paper b3 times. Though, both Alice and Bob did not choose the sequence in which they show things. It is guaranteed that a1+a2+a3=n and b1+b2+b3=n.

Your task is to find two numbers:

the minimum number of round Alice can win;
the maximum number of rounds Alice can win.
Input
The first line of the input contains one integer n (1≤n≤109) — the number of rounds.

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

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

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

Examples
inputCopy
2
0 1 1
1 1 0
outputCopy
0 1
inputCopy
15
5 5 5
5 5 5
outputCopy
0 15
inputCopy
3
0 0 3
3 0 0
outputCopy
3 3
inputCopy
686
479 178 29
11 145 530
outputCopy
22 334
inputCopy
319
10 53 256
182 103 34
outputCopy
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.

solution

/*
题意:
+ 石头剪刀布,进行n轮。给出a1,a2,a3,b1,b2,b3分别表示A和B总共出的三种的次数(加起来为n)
+ 求A可以获胜的最小次数和最大次数。
思路:
+ A赢的最大次数可以直接算,每次都让B出对应被A克的累加就行。
+ 但是A赢的情况不能直接算B获胜次数,还有平局,所以直接拿n-B输了的状态和a取最小累加。
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e6+10;
const int mod = 998244353;
int main(){
	int n,a1,a2,a3,b1,b2,b3;
	cin>>n>>a1>>a2>>a3>>b1>>b2>>b3;
	int ans1 = min(a1,n-b2)+min(a2,n-b3)+min(a3,n-b1);
	int ans2 = min(a1,b2)+min(a2,b3)+min(a3,b1);
	cout<<n-ans1<<" "<<ans2<<"\n";
	return 0;
}



  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

文章来源: gwj1314.blog.csdn.net,作者:小哈里,版权归原作者所有,如需转载,请联系作者。

原文链接:gwj1314.blog.csdn.net/article/details/113951341

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。