RPSSL - Rock-Paper-Scissors-Lizard-Spock

no tags 

Daniel enjoys watching TV series. One of his favorite is "The Big Bang Theory". The main characters of this series are: Sheldon – genius theoretical physicist, his friend Leonard – talented experimental physicist, their attractive, blonde neighbor Penny, and also their friends an aerospace engineer Howard and a particle astrophysicist Rajesh.
One time Rajesh tells Sheldon:
“I'll tell you what. How about we go rock-paper-scissors?”
“Ooh”, – Sheldon replies – “I don't think so. Anecdotal evidence suggests that in the game of rock-paper-scissors, players familiar with each other will tie 75 to 80% of the time due to the limited number of outcomes. I suggest rock-paper-scissors-lizard-Spock”.
“What?”
“It's very simple. Scissors cuts paper. Paper covers rock. Rock crushes lizard. Lizard poisons Spock. Spock smashes scissors. Scissors decapitates lizard. Lizard eats paper. Paper disproves Spock. Spock vaporizes rock. And as it always has, rock crushes scissors”.
“Okay, I think I got it”.
And the friends decided to play rock-paper-scissors-lizard-Spock. And we would determine what the probability that Rajesh beats Sheldon in this game. We know the probabilities that any of the friends choose any object in the game. Also we know that they play till two wins, so the winner of the game is the person who first wins two rounds.

Input

The first line of input contains the number t - the number of tests. Next comes the description of t tests. Each test case consists of two lines. The first line contains five integers RR, RSc, RP, RL, RSp – the probabilities that Rajesh chooses rock, scissors, paper, lizard or Spock respectively. The second line contains five integers SR, SSc, SP, SL, SSp – the probabilities that Sheldon chooses rock, scissors, paper, lizard or Spock respectively. (Note: the order of the objects in the input is rock, scissors, paper, lizard, Spock. The original problem is in Russian and we have scissors before paper in Russian variant of the game. Otherwise the rules are the same.)

Constraints

1 <= t <= 500
0 <= RR, RSc, RP, RL, RSp <= 100, RR + RSc + RP + RL + RSp = 100
0 <= SR, SSc, SP, SL, SSp <= 100, SR + SSc + SP + SL + SSp = 100

Output

For each test case print the probability that Rajesh beats Sheldon in percent rounded to the nearest integer.

Example

Input:
2
10 20 30 40 0
10 10 10 10 60
20 20 20 20 20
20 20 20 20 20

Output:
66
50

hide comments
smso: 2021-03-08 14:56:32

1. Take different no. of draws into consideration.
2. Add 0.5 to a double before casting to int.

Ouditchya Sinha: 2013-05-06 14:24:41

Nice Problem. Do consider tie cases, costed me some WAs. :)

Rajarshi Sarkar: 2013-04-30 03:22:31

The answer of 1st test case is 66 (correctly mentioned by the problem setter)
So , enough said ! As far the show is concerned Rsp=Ssp=100 :D

# BAZINGA :P

Last edit: 2013-05-01 09:33:09
Akagami: 2012-12-31 06:46:42

got ac after many wa's. Try
1
100 0 0 0 0
100 0 0 0 0
output:0

Suvodeep Pyne: 2012-12-23 22:42:28

No .. 66 is fine.

Abhishek Kandoi: 2012-12-12 17:29:43

I am getting WA when I submit even though I am able to get the test cases working successfully.
Please provide with some tricky test cases.

Last edit: 2012-12-12 17:30:07
Akagami: 2012-08-26 19:13:05

more test cases please.and is the ans for 1st test case 66 or 67?

DaRksTar: 2012-06-15 19:52:56

good ques!

Rishabh Maurya: 2010-08-06 21:02:52

I am getting correct output for the given test cases , but getting wrong answer on submission. Please provide me some more test cases so that i could verify my solution.

Thank you

Last edit: 2010-08-06 21:09:46
numerix: 2010-08-05 06:20:49

You are wrong.


Added by:Spooky
Date:2010-03-17
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS OBJC PERL6 SQLITE VB.NET
Resource:Advancement Spring 2010, http://sevolymp.uuuq.com/