A. Singhal and Swap

Codeforces
IDCF10276A
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
_If you want to practice topicwise questions in the ladder way like a2oj , do register on my site *http://codedigger.tech* after the contest. Here you will get Handpicked Topicwise Questions from codeforces, codechef, uva and spoj for your better practice. Best of Luck._ Singhal has two strings $S$ and $T$ consisting of lowercase English Letters. He wants to obtain string $S$ lexicographically smallest possible. He can do the following operation any number of times: choose an index $p o s_1$ in the string $S$, choose an index $p o s_2$ in the string $T$, and swap $s_{p o s_1}$ with $t_{p o s_2}$. String $p$ is lexicographically smaller than string $q$, For example, _abc_ is lexicographically smaller than _abcd_ , _abd_ is lexicographically smaller than _abec_ , _afa_ is not lexicographically smaller than _ab_ and _a_ is not lexicographically smaller than _a_. *Note: You have not to minimize number of operations and any index of both string can be chosen more than once.* The first line contains a single integer $t (1 <= t <= 100)$ — the number of test cases in the input. Then $t$ test cases follow. Each query contains two lines. The first line contains a string $S (1 <= | S | <= 100)$ , and the second line contains a string $T (1 <= | T | <= 100)$. $| S |$ and $| T |$ is the length of the string $S$ and $T$ respectively. *Note: Both strings will have only lowercase English Letters.* For each test from the input print lexicographical smallest possible string $S$. Print the answers to the tests in the order in which the tests are given in the input. In the first query — swap($s_2, t_1$) to get smallest lexicographical possible. In the second query — swap($s_2, t_1$) to get $S$ = _aac_ and $T$ = _bbc_, then swap($s_3, t_1$)to get $S$ = _aab_. ## Input The first line contains a single integer $t (1 <= t <= 100)$ — the number of test cases in the input. Then $t$ test cases follow.Each query contains two lines. The first line contains a string $S (1 <= | S | <= 100)$ , and the second line contains a string $T (1 <= | T | <= 100)$. $| S |$ and $| T |$ is the length of the string $S$ and $T$ respectively.*Note: Both strings will have only lowercase English Letters.* ## Output For each test from the input print lexicographical smallest possible string $S$. Print the answers to the tests in the order in which the tests are given in the input. [samples] ## Note In the first query — swap($s_2, t_1$) to get smallest lexicographical possible.In the second query — swap($s_2, t_1$) to get $S$ = _aac_ and $T$ = _bbc_, then swap($s_3, t_1$)to get $S$ = _aab_.
**Definitions** Let $ T \in \mathbb{Z} $ be the number of test cases. For each test case $ k \in \{1, \dots, T\} $, let $ r_k, b_k \in \mathbb{Z} $ denote the number of red and blue balls, respectively. **Constraints** 1. $ 1 \le T \le 10 $ 2. For each $ k \in \{1, \dots, T\} $: $ 1 \le r_k, b_k \le 100 $ **Objective** For each test case $ k $, compute the probability $ P_k $ of selecting two red balls without replacement: $$ P_k = \frac{\binom{r_k}{2}}{\binom{r_k + b_k}{2}} = \frac{r_k(r_k - 1)}{(r_k + b_k)(r_k + b_k - 1)} $$ Express $ P_k $ as an irreducible fraction $ \frac{A}{B} $, where $ A, B \in \mathbb{Z} $, $ \gcd(A, B) = 1 $, and $ B > 0 $. If $ P_k = 0 $, output $ 0/1 $; if $ P_k = 1 $, output $ 1/1 $.
API Response (JSON)
{
  "problem": {
    "name": "A. Singhal and Swap",
    "description": {
      "content": "_If you want to practice topicwise questions in the ladder way like a2oj , do register on my site *http://codedigger.tech* after the contest. Here you will get Handpicked Topicwise Questions from code",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10276A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "_If you want to practice topicwise questions in the ladder way like a2oj , do register on my site *http://codedigger.tech* after the contest. Here you will get Handpicked Topicwise Questions from code...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case $ k \\in \\{1, \\dots, T\\} $, let $ r_k, b_k \\in \\mathbb{Z} $ denote the number of red and blue balls, respect...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments