Hrbeu stone scissors cloth 1

Source: Internet
Author: User

Stone scissors cloth 1

Timelimit: 1 second memorylimit: 32
Megabyte

Totalsubmit: 73 accepted: 30

Description

After winter vacation, X is bored at home. So he came up with a new stone scissors cloth (single-host ).

The method is as follows: S represents stone, j Represents scissors, and B Represents cloth. If you win one point, you will not be scored. If you lose one point, you will be deducted. Play n times, and each time the opponent plays a game, everything is known. However, you can only output a s, B j, and c B (A, B, C are both non-negative and A + B + C = N ).

Now, how do you arrange for a S, B j, and c B to maximize your final score.

Input

N (n <= 100) is given first, indicating the number of games. Next, we will give n strings consisting of S, J, and B to indicate what the opponent is after each game. Finally, A, B, and C are given.

When n = 0, the input ends.

Output

An integer is given for each group of test data, indicating the maximum score that X can win in this game.

Sample Input

2

Jj

2 0 0

0

Sample output

2

Source

Author: xiaoz

 

# Include <cstdio>
# Include <cmath>
# Include <algorithm>
Using namespace STD;
Int N, A1, A2, B1, B2, C1, C2, sum = 0, sum2 = 0;
Char ch;
Int main (){
While (~ Scanf ("% d", & N), n ){
A1 = b1 = C1 = 0;
Getchar ();
While (CH = getchar ())! = '\ N '){
If (CH = 'J') B1 ++;
If (CH = 's') A1 ++;
If (CH = 'B') C1 ++;
}
Scanf ("% d", & A2, & B2, & C2 );
Sum = min (A2, B1) + min (B2, C1) + min (C2, A1 );
If (a2-b1> 0 ){
A2 = a2-b1;
B1 = 0;
}
Else {
B1 = b1-a2;
A2 = 0;
}
If (b2-c1> 0 ){
B2 = b2-c1;
C1 = 0;
}
Else {
C1 = c1-b2;
B2 = 0;
}
If (c2-a1> 0 ){
C2 = c2-a1;
A1 = 0;
}
Else {
A1 = a1-c2;
C2 = 0;
}
Sum2 = min (a1, a2) + min (b1, b2) + min (C1, C2 );
Sum = sum-(n-sum2-sum );
Printf ("% d \ n", sum );
}
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.