P2987 [USACO10MAR] StarCowraft G

Description

The beta version of StarCowraft II is ready! Farmer John and Bessie are testing it, trying different strategies in one-on-one battles against each other’s armies. The goal in StarCowraft II is to defeat your opponent’s army in a battle. Each player’s army fights in a battle. An army comprises up to three different types of units with respective strengths denoted by constant positive real numbers unknown to the players: cattlebruisers with strength S1, cow templars with strength S2, and ultracows with strength S3. The only given bounding information is that no unit is more than 100 times as strong as any other unit. An army’s total strength is the sum of the individual strengths of each of its units. For example, an army that has, among other units, 23 cattlebruisers would gain 23*S1 strength just from the cattlebruisers. When two opposing armies fight in a battle, the army with the higher total strength value wins. If the armies have exactly equal strength values, one of the players wins at random. Farmer John and Bessie played N (0

Input Format

* Line 1: Two space-separated integers: N and M. * Lines 2..N+1: Line i+1 describes a test battle with seven space-separated items — a victory letter and six space-separated integer unit counts: V\_i, J1\_i, J2\_i, J3\_i, B1\_i, B2\_i, and B3\_i. * Lines N+2..N+M+1: Line i+N+1 describes a new battle using six space-separated integers: J1\_i, J2\_i, J3\_i, B1\_i, B2\_i, and B3\_i.

Output Format

* Lines 1..M: Line i contains the outcome of the i-th new battle: ‘J’ if Farmer John definitely wins, ‘B’ if Bessie definitely wins, and ‘U’ (undecidable) if it is impossible to decide the winner with the given information.

Explanation/Hint

The first two games correspond to the examples in the description. The result of the last game cannot be determined with only the information that Farmer John and Bessie currently have. Specifically, both S1 = 9.0, S2 = 7.0, S3 = 4.0 and S1 = 12.0, S2 = 20.0, S3 = 10.0 are consistent with the “test battles,” but they give different results when plugged into the third “new battle.” Translated by ChatGPT 5