#P4459. [BJOI2018] 双人猜数游戏

    ID: 3384 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2018各省省选北京提交答案枚举,暴力

[BJOI2018] 双人猜数游戏

Description

Alice and Bob are very smart; they can figure out optimal strategies for all kinds of games. A variety show "The Strongest Boss" invites them to play a game. The host writes three positive integers s,m,ns, m, n, then tells Alice and Bob together that smns \le m \le n and what ss is. (That is, ss is the lower bound for the m,nm, n to be guessed.) Then the host privately tells Alice what m×nm \times n is, and privately tells Bob what m+nm + n is.

Of course, if one person knows both m×nm \times n and m+nm + n, they can easily compute mm and nn, but now Alice and Bob each know only one of them, and they can only answer the host’s questions without communicating. Starting from one of them, the host alternately asks the current respondent, “Do you know what mm and nn are?” The respondent can only answer “know” or “don’t know.”

For show effects and to demonstrate Alice and Bob’s brilliance, the host wants that after a total of tt “don’t know” answers, both Alice and Bob will know what mm and nn are. Now the host asks you to construct a pair mm and nn that satisfies the requirements.

Input Format

A single line in the form s <name> t (where <name> is Alice or Bob), where ss is the lower bound for the numbers to guess, <name> is the person the host asks first, and tt is the total number of “don’t know” answers from Alice and Bob.

Output Format

Output two integers mm and nn (separated by a space), representing one valid solution. If there are multiple solutions, output the one with the smallest m+nm + n. If there are still multiple, among those with minimal m+nm + n, output the one with the smallest mm.

5 Bob 2

6 10
2 Alice 3
4 4

Hint

Sample 1 Explanation

The host tells Alice and Bob that 5mn5 \le m \le n, privately tells Alice m×n=60m \times n = 60, and privately tells Bob m+n=16m + n = 16. The questioning process:

  • The host asks Bob; Bob says “don’t know.”
  • The host asks Alice; Alice says “don’t know.”
  • The host asks Bob; Bob says “know.”
  • The host asks Alice; Alice says “know.”

Sample 2 Explanation

The host tells Alice and Bob that 2mn2 \le m \le n, privately tells Alice m×n=16m \times n = 16, and privately tells Bob m+n=8m + n = 8. The questioning process:

  • The host asks Alice; Alice says “don’t know.”
  • The host asks Bob; Bob says “don’t know.”
  • The host asks Alice; Alice says “don’t know.”
  • The host asks Bob; Bob says “know.”
  • The host asks Alice; Alice says “know.”

Constraints and Conventions

  • For 40%40\% of the testdata, t=2t = 2.
  • For 100%100\% of the testdata, 1s2001 \le s \le 200, 2t152 \le t \le 15, and a solution exists.

Translated by ChatGPT 5