E. Rock, Paper, Scissors(有趣的思维题) Codeforces Round #674 (Div. 3)

127 篇文章 3 订阅

原题链接: https://codeforces.com/contest/1426/problem/E

在这里插入图片描述
测试样例

input
2
0 1 1
1 1 0
output
0 1
input
15
5 5 5
5 5 5
output
0 15
input
3
0 0 3
3 0 0
output
3 3
input
686
479 178 29
11 145 530
output
22 334
input
319
10 53 256
182 103 34
output
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进行石头剪刀布游戏,其中进行了 n n n次回合,Alice出了 a 1 a_1 a1次石头, a 2 a_2 a2次剪刀, a 3 a_3 a3次布。Bob出了 b 1 b_1 b1次石头, b 2 b_2 b2次剪刀, b 3 b_3 b3次布。显然有一个事实就是 a 1 + a 2 + a 3 = b 1 + b 2 + b 3 = = n a_1+a_2+a_3=b_1+b_2+b_3==n a1+a2+a3=b1+b2+b3==n。问Alice赢得最少回合数和赢得最多回合数。

解题思路: 求最多回合数自然简单,考虑Alice赢的就行。自然是 m i n ( a 1 + b 2 ) + m i n ( a 2 + b 3 ) + m i n ( a 3 + b 1 ) min(a_1+b_2)+min(a_2+b_3)+min(a_3+b_1) min(a1+b2)+min(a2+b3)+min(a3+b1) 那么关键是求赢得最小回合数,你可能会想了,让对手赢得最多,再用 n n n减去这个值不就行了吗?这自然是错误的,因为还存在平局,如果我们以这种思路的话,我们是需要剔除平局的。那么我们怎么来衡量这个比重呢?其实我暂时也还不知道,贴一下大佬代码。之后补最小值解决方案。

AC代码

/*
*邮箱:unique_powerhouse@qq.com
*blog:https://me.csdn.net/hzf0701
*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*
*/
#include<bits/stdc++.h>	//POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

using namespace std;

const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>  pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//

int n;
int a1,a2,a3;
int b1,b2,b3;
int main(){
	//freopen("in.txt", "r", stdin);//提交的时候要注释掉
	IOS;
	while(cin>>n){
		cin>>a1>>a2>>a3;
		cin>>b1>>b2>>b3;
		int maxx=min(a1,b2)+min(a2,b3)+min(a3,b1);//获取最大值。
		int minn=n-(min(a2,b1+b2)+min(a3,b2+b3)+min(a1,b3+b1));
		cout<<minn<<" "<<maxx<<endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HeZephyr

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值