No.3633 Rabbit and turtle
タグ : / 解いたユーザー数 31
作問者 : 👑
Problem Statement
A rabbit and a turtle are now going to compete to see how far each can advance in $10^{100}$ turns.
At the start, the distance traveled is $0$ for both the rabbit and the turtle.
The rabbit and the turtle each advance according to the following rules.
-
Rabbit: On the first turn, it advances by $A$ and sets its fatigue to $D$.
After that, its action on each turn is determined as follows.- If its fatigue is greater than $0$, it does not advance, and its fatigue decreases by $R$.
- If its fatigue is $0$ or less, it advances by $A$, and its fatigue increases by $D$.
-
Turtle: It advances by $B$ every turn.
Determine which of them wins, that is, which of them has traveled the longer distance after $10^{100}$ turns.
Note that a tie is also possible.
You are given $T$ test cases; answer each of them.
Constraints
- $1 \leqq B \leqq A \leqq 10^{9}$
- $1 \leqq R \leqq D \leqq 10^{9}$
- $1 \leqq T \leqq 10^5$
- All inputs are integers.
Input
$T$ $testcase_1$ $testcase_2$ $\vdots$ $testcase_T$
Each test case is given in the following format.
$A\ B\ D\ R$
Output
For each test case, print rabbit if the rabbit wins, turtle if the turtle wins, and tie if it is a tie. The output consists of $T$ lines.
Print a newline at the end.
Sample
Sample 1
Input
3 3 1 1 1 1 1 2 1 4 2 1 1
Output
rabbit turtle tie
Test case $1$ proceeds as follows.
Turn $1$: Since it is the first turn, the rabbit advances by $3$ and sets its fatigue to $1$. The turtle advances by $1$.
Turn $2$: The rabbit recovers $1$ fatigue, bringing it to $0$. The turtle advances by $1$.
In total, the rabbit has advanced $3$ and the turtle has advanced $2$.
Turn $3$: Since the rabbit's fatigue is $0$, it advances by $3$ and sets its fatigue to $1$. The turtle advances by $1$.
In total, the rabbit has advanced $6$ and the turtle has advanced $3$.
Turn $4$: The rabbit recovers $1$ fatigue, bringing it to $0$. The turtle advances by $1$.
In total, the rabbit has advanced $6$ and the turtle has advanced $4$.
Turn $5$: Since the rabbit's fatigue is $0$, it advances by $3$ and sets its fatigue to $1$. The turtle advances by $1$.
In total, the rabbit has advanced $9$ and the turtle has advanced $5$.
From this progression, the rabbit ultimately travels the longer distance.
Also, note that the match can end in a tie, as in test case $3$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。