CF1459A.Red-Blue Shuffle

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn cards numbered 1,,n1, \ldots, n . The card ii has a red digit rir_i and a blue digit bib_i written on it.

We arrange all nn cards in random order from left to right, with all permutations of 1,,n1, \ldots, n having the same probability. We then read all red digits on the cards from left to right, and obtain an integer RR . In the same way, we read all blue digits and obtain an integer BB . When reading a number, leading zeros can be ignored. If all digits in a number are zeros, then the number is equal to 00 . Below is an illustration of a possible rearrangement of three cards, and how RR and BB can be found.

Two players, Red and Blue, are involved in a bet. Red bets that after the shuffle R>BR > B , and Blue bets that R<BR < B . If in the end R=BR = 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 TT ( 1T1001 \leq T \leq 100 ) — the number of test cases.

Descriptions of TT test cases follow. Each test case description starts with a line containing a single integer nn ( 1n10001 \leq n \leq 1000 ) — the number of cards.

The following line contains a string of nn digits r1,,rnr_1, \ldots, r_n — red digits on cards 1,,n1, \ldots, n respectively.

The following line contains a string of nn digits b1,,bnb_1, \ldots, b_n — blue digits on cards 1,,n1, \ldots, n respectively.

Note that digits in the same line are not separated with any delimiters.

输出格式

Print TT 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 nRn_R be the number of permutations of cards 1,,n1, \ldots, n such that the resulting numbers RR and BB satisfy R>BR > B . Similarly, let nBn_B be the number of permutations such that R<BR < B . If nR>nBn_R > n_B , you should print "RED". If nR<nBn_R < n_B , you should print "BLUE". If nR=nBn_R = n_B , print "EQUAL".

In the first sample case, R=777R = 777 and B=111B = 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:

  1. order 1,2,31, 2, 3 : 314>159314 > 159 ;
  2. order 1,3,21, 3, 2 : 341>195341 > 195 ;
  3. order 2,1,32, 1, 3 : 134<519134 < 519 ;
  4. order 2,3,12, 3, 1 : 143<591143 < 591 ;
  5. order 3,1,23, 1, 2 : 431<915431 < 915 ;
  6. order 3,2,13, 2, 1 : 413<951413 < 951 .
    Since R<BR < B is more frequent, the answer is "BLUE".

In the third sample case, R=BR = B regardless of the card order, thus the bet is always a draw, and both Red and Blue have zero chance to win.

首页