Logo
(追記) (追記ここまで)

18624번 - Flaaffy 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
15 초 512 MB177685.714%

문제

So you want to see how Pok´emon play games, eh? It’s a good day for you — Flaaffy, a sheep-like electric Pok´emon, just found an electronic Number Guessing BoardTM and it wants to have fun with it!

The board is a five-digit electronic display that can show all integers from 0 to 99 999. When Flaaffy turned it on, all five digits were initially set to 0. On its startup, the board chose a secret integer x in the interval [L, R]. Flaaffy wants to guess this number. It can use electric shocks to operate the board in two following ways:

  • Change a single digit on the display.
  • Ask the board if x is smaller, equal or larger than the number shown on the display.

The game ends if Flaaffy can correctly determine what the hidden number is.

However, each operation depletes the amount of electricity stored by Flaaffy. Therefore, it wants to determine the hidden number in the minimum possible number of shocks. Flaaffy already figured out the optimal strategy, can you?

입력

The first line contains a single integer t (1 ≤ t ≤ 50) — the number of independent testcases in the file. Each of the following t lines describes a single testcase and contains two integers L, R (1 ≤ L < R ≤ 99 999).

출력

For each testcase, output a single number — the minimum number of shocks Flaaffy needs to produce in order to correctly guess the hidden number.

제한

예제 입력 1

3
97 107
12043 12045
61 69

예제 출력 1

6
5
7

힌트

Here is the decision tree for the first testcase:

Each edge means either changing one digit or comparing x with the number currently on the display. In the leaves of the tree Flaaffy is already sure what the hidden number is.

출처

Camp > Petrozavodsk Programming Camp > Summer 2019 > Day 5: Radewoosh + mnbvmar Contest F번

Contest > Open Cup > 2019/2020 Season > Stage 2: Grand Prix of Warsaw F번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /