CF Rock, Paper, Scissors
链接: 原题地址.
题目
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
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的剪刀布石头的数量,取小值加入总场数。
然后是最少的胜场,最小的胜场就是要首先找平手和输的场数,减去便是最少的胜场。首先你可以发现,A的石头可以用B的石头进行平局的场次,或是B的布进行输的场次,那么说明如果A的石头存在,那么B的石头和布必定为零,而因为两者的场次相同,A的石头存在,那B必定有场次存在且必为剪刀;而当A的石头不存在时,说明B的石头存在或也不存在,当B的石头不存在时,就无法判断,选择其他的剪刀或者布重新判断,而当B的石头存在时,说明A的剪刀和石头都已经用完了,因为当这两个存在时,B的石头就能用来消耗了,因此A只剩下布了,即这也是最小胜场数了。
因此,最终AB所有输或者平局场数打完后,剩下的便是胜场且只有一种赢法,那么只要计算哪一种剩下即可了。
代码
map<string,ll>mp,mp2;
ll t,n,m,a,b,c;
int main() {
speed();
cin>>t;
cin>>mp["shitou"]>>mp["jiandao"]>>mp["bu"];
cin>>mp2["shitou"]>>mp2["jiandao"]>>mp2["bu"];
ll maxx=min(mp["shitou"],mp2["jiandao"])+min(mp["jiandao"],mp2["bu"])+min(mp["bu"],mp2["shitou"]);
ll minn=max(mp["shitou"]-mp2["bu"]-mp2["shitou"],(ll)0)+max(mp["jiandao"]-mp2["shitou"]-mp2["jiandao"],(ll)0)+max(mp["bu"]-mp2["jiandao"]-mp2["bu"],(ll)0);
cout<<minn<<" "<<maxx<<endl;
return 0;
}