#P13146. [GCJ 2018 #2] Graceful Chainsaw Jugglers

    ID: 15011 远端评测题 25000ms 1024MiB 尝试: 0 已通过: 0 难度: 4 上传者: 标签>动态规划 DP2018记忆化搜索Google Code Jam

[GCJ 2018 #2] Graceful Chainsaw Jugglers

题目描述

You are the manager of the Graceful Chainsaw Jugglers performance group, and you are trying to succeed in the very competitive chainsaw juggling business. You have an unlimited number of identical talented jugglers, and each of them knows how to juggle any number of chainsaws. To run a show, you will choose some number of jugglers, and then distribute your red chainsaws and blue chainsaws among them, so that each juggler gets at least one chainsaw. For example, one juggler might juggle two red chainsaws and three blue chainsaws, and another juggler might juggle just one red chainsaw. During the show, each chainsaw is used by only one juggler; the jugglers do not pass chainsaws around, because it is already hard enough just to juggle them!

According to your market research, your audience is happiest when the show uses as many jugglers and chainsaws as possible, but the audience also demands variety: no two jugglers in the show can use both the same number of red chainsaws and the same number of blue chainsaws.

You have RR red chainsaws and BB blue chainsaws, and you must use all of them in the show. What is the largest number of jugglers that you can use in the show while satisfying the audience's demands?

输入格式

The first line of the input gives the number of test cases, TT; TT test cases follow. Each test case consists of one line with two integers RR and BB: the numbers of red and blue chainsaws that you must use in the show.

输出格式

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the largest number of jugglers that you can use in the show while satisfying the audience's demands, as described above.

2
2 0
4 5
Case #1: 1
Case #2: 5

提示

Sample Explanation

In Sample Case #1, the only possible strategy is to give both red chainsaws to one juggler.

In Sample Case #2, one optimal strategy is to have:

  • one juggler with one red chainsaw
  • one juggler with two red chainsaws
  • one juggler with one blue chainsaw
  • one juggler with three blue chainsaws
  • one juggler with one red chainsaw and one blue chainsaw

Limits

  • 1T1001 \leq T \leq 100.
  • R+B>0R + B > 0.

Test set 1 (7 Pts, Visible)

  • 0R500 \leq R \leq 50.
  • 0B500 \leq B \leq 50.

Test set 2 (17 Pts, Hidden)

  • 0R5000 \leq R \leq 500.
  • 0B5000 \leq B \leq 500.