308054: CF1459A. Red-Blue Shuffle

Memory Limit:512 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Red-Blue Shuffle

题意翻译

### 题意翻译 ### 题目描述 有 $n$ 张卡,第 $i$ 张卡上有一个红色的数码 $R_i$ 和一个蓝色的数码 $B_i$ 。如果将牌随机洗好后从左到右摆放(即`random_shuffle`)后,令红色的数码从左到右连起来**严格大于**蓝色的数码概率为 $r$ ;红色的数码连起来**严格小于**蓝色的数码为 $b$ 。 如果 $r>b$ ,输出`RED`; 如果 $r<b$ ,输出`BLUE`; 否则输出`EQUAL`。 ### 输入格式 第一行输入 $T$ ,表示数据组数。 对于每一个数据,第一行输入 $n$ ,表示卡的个数。 接下来输入两个字符串 $R, B$ ,其中 $R_i, B_i$ 分别表示第 $i$ 张卡的红色数码、蓝色数码。 ### 输出格式 对于每一组数据输出一行字符串,表示该组数据的答案。

题目描述

There are $ n $ cards numbered $ 1, \ldots, n $ . The card $ i $ has a red digit $ r_i $ and a blue digit $ b_i $ written on it. We arrange all $ n $ cards in random order from left to right, with all permutations of $ 1, \ldots, 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. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1459A/e40cf4ff40332b751ba1a670952b53fac268a100.png)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.

输入输出格式

输入格式


The first line contains a single integer $ T $ ( $ 1 \leq T \leq 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 \leq n \leq 1000 $ ) — the number of cards. The following line contains a string of $ n $ digits $ r_1, \ldots, r_n $ — red digits on cards $ 1, \ldots, n $ respectively. The following line contains a string of $ n $ digits $ b_1, \ldots, b_n $ — blue digits on cards $ 1, \ldots, n $ respectively. Note that digits in the same line are not separated with any delimiters.

输出格式


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.

输入输出样例

输入样例 #1

3
3
777
111
3
314
159
5
09281
09281

输出样例 #1

RED
BLUE
EQUAL

说明

Formally, let $ n_R $ be the number of permutations of cards $ 1, \ldots, n $ such that the resulting numbers $ R $ and $ B $ satisfy $ R > B $ . Similarly, let $ n_B $ be the number of permutations such that $ R < B $ . If $ n_R > n_B $ , you should print "RED". If $ n_R < n_B $ , you should print "BLUE". If $ n_R = n_B $ , 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: 4. order $ 1, 2, 3 $ : $ 314 > 159 $ ; 5. order $ 1, 3, 2 $ : $ 341 > 195 $ ; 6. order $ 2, 1, 3 $ : $ 134 < 519 $ ; 7. order $ 2, 3, 1 $ : $ 143 < 591 $ ; 8. order $ 3, 1, 2 $ : $ 431 < 915 $ ; 9. 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.

Input

题意翻译

### 题意翻译 ### 题目描述 有 $n$ 张卡,第 $i$ 张卡上有一个红色的数码 $R_i$ 和一个蓝色的数码 $B_i$ 。如果将牌随机洗好后从左到右摆放(即`random_shuffle`)后,令红色的数码从左到右连起来**严格大于**蓝色的数码概率为 $r$ ;红色的数码连起来**严格小于**蓝色的数码为 $b$ 。 如果 $r>b$ ,输出`RED`; 如果 $r<b$ ,输出`BLUE`; 否则输出`EQUAL`。 ### 输入格式 第一行输入 $T$ ,表示数据组数。 对于每一个数据,第一行输入 $n$ ,表示卡的个数。 接下来输入两个字符串 $R, B$ ,其中 $R_i, B_i$ 分别表示第 $i$ 张卡的红色数码、蓝色数码。 ### 输出格式 对于每一组数据输出一行字符串,表示该组数据的答案。

加入题单

算法标签: