CF1459A.Red-Blue Shuffle
入门
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n cards numbered 1,…,n. The card i has a red digit ri and a blue digit bi written on it.
We arrange all n cards in random order from left to right, with all permutations of 1,…,n having the same probability. We then read all red digits on the cards from left to right, and obtain an integer R. In the same way, we read all blue digits and obtain an integer B. When reading a number, leading zeros can be ignored. If all digits in a number are zeros, then the number is equal to 0. Below is an illustration of a possible rearrangement of three cards, and how R and B can be found.

Two players, Red and Blue, are involved in a bet. Red bets that after the shuffle R>B, and Blue bets that R<B. If in the end R=B, the bet results in a draw, and neither player wins.
Determine, which of the two players is more likely (has higher probability) to win the bet, or that their chances are equal. Refer to the Note section for a formal discussion of comparing probabilities.
有 n 张编号为 1,…,n 的卡片。卡片 i 上写有一个红色数字 ri 和一个蓝色数字 bi。
我们将全部 n 张卡片以随机顺序从左到右排列,所有 1,…,n 的排列出现概率均相同。然后,我们从左到右依次读取所有卡片上的红色数字,得到一个整数 R;同理,从左到右依次读取所有蓝色数字,得到一个整数 B。在读取一个数时,前导零可被忽略;若一个数的所有数字均为零,则该数等于 0。下图展示了一种三张卡片的可能重排方式,以及如何由此得到 R 和 B。

两名玩家——红方(Red)与蓝方(Blue)——参与一场赌局。红方押注洗牌后 R>B,蓝方押注 R<B。若最终 R=B,则赌局为平局,双方均未获胜。
请判断:两名玩家中哪一方获胜的概率更高,抑或双方获胜概率相等。有关概率比较的严格讨论,请参见“注意”(Note)部分。
输入格式
The first line contains a single integer T (1≤T≤100) — the number of test cases.
Descriptions of T test cases follow. Each test case description starts with a line containing a single integer n (1≤n≤1000) — the number of cards.
The following line contains a string of n digits r1,…,rn — red digits on cards 1,…,n respectively.
The following line contains a string of n digits b1,…,bn — blue digits on cards 1,…,n respectively.
Note that digits in the same line are not separated with any delimiters.
第一行包含一个整数 T(1≤T≤100),表示测试用例的数量。
接下来是 T 个测试用例的描述。每个测试用例的描述以一行开始,该行包含一个整数 n(1≤n≤1000),表示卡片的数量。
下一行包含一个长度为 n 的数字字符串 r1,…,rn,分别表示第 1,…,n 张卡片上的红色数字。
再下一行包含一个长度为 n 的数字字符串 b1,…,bn,分别表示第 1,…,n 张卡片上的蓝色数字。
注意:同一行中的数字之间不使用任何分隔符。
输出格式
Print T answers for the test cases in order, one per line.
If Red has a strictly higher change to win, print "RED".
If Blue has a strictly higher change to win, print "BLUE".
If both players are equally likely to win, print "EQUAL".
Note that all answers are case-sensitive.
按顺序输出 T 个测试用例的答案,每个答案占一行。
如果红色方获胜的概率严格更高,则输出 "RED"。
如果蓝色方获胜的概率严格更高,则输出 "BLUE"。
如果双方获胜的概率相等,则输出 "EQUAL"。
注意:所有答案均区分大小写。
输入输出样例
输入#1
3 3 777 111 3 314 159 5 09281 09281
输出#1
RED BLUE EQUAL
说明/提示
Formally, let nR be the number of permutations of cards 1,…,n such that the resulting numbers R and B satisfy R>B. Similarly, let nB be the number of permutations such that R<B. If nR>nB, you should print "RED". If nR<nB, you should print "BLUE". If nR=nB, print "EQUAL".
In the first sample case, R=777 and B=111 regardless of the card order, thus Red always wins.
In the second sample case, there are two card orders when Red wins, and four card orders when Blue wins:
- order 1,2,3: 314>159;
- order 1,3,2: 341>195;
- order 2,1,3: 134<519;
- order 2,3,1: 143<591;
- order 3,1,2: 431<915;
- order 3,2,1: 413<951.
Since R<B is more frequent, the answer is "BLUE".
In the third sample case, R=B regardless of the card order, thus the bet is always a draw, and both Red and Blue have zero chance to win.
形式化地,设 nR 为卡片 1,…,n 的所有排列中,使得最终得到的数字 R 和 B 满足 R>B 的排列数目;类似地,设 nB 为满足 R<B 的排列数目。若 nR>nB,则输出 "RED";若 nR<nB,则输出 "BLUE";若 nR=nB,则输出 "EQUAL"。
在第一个样例中,无论卡片如何排列,均有 R=777 且 B=111,因此红方始终获胜。
在第二个样例中,红方获胜的卡片排列有 2 种,蓝方获胜的卡片排列有 4 种:
- 排列 1,2,3:314>159;
- 排列 1,3,2:341>195;
- 排列 2,1,3:134<519;
- 排列 2,3,1:143<591;
- 排列 3,1,2:431<915;
- 排列 3,2,1:413<951。
由于 R<B 出现得更频繁,答案为 "BLUE"。
在第三个样例中,无论卡片如何排列,总有 R=B,因此该赌局总是平局,红方与蓝方获胜的概率均为零。
输入解题思路,AI测评打分。不知道怎么写?