QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100

#9675. 电池检测

统计

小 F 有一个手电筒,需要放入两个有电的电池才能使用。他现在有很多电池,但其中有一些没有电了,具体而言,有 $a$ 个有电的电池和 $b$ 个没电的电池。他唯一能做的就是装入两个电池,并观察手电筒是否点亮。小 F 在知道有 $a$ 个电池有电,$b$ 个电池没有电的前提下,采取最优策略。他想要知道,最坏的情况下,至少需要检测多少次才能使手电筒亮起来。

下面是一个简单的例子,假设 $a=2,b=1$,将电池编号为 $1,2,3$,第一次测 $1,2$ 号电池,手电筒没有亮,第二次测 $1,3$ 号电池,手电筒没有亮,第三次测 $2,3$ 号电池,手电筒亮了。可以证明,无论使用什么策略,在最坏情况下,一定要三次检测才能让手电筒亮起来。

输入格式

第一行一个正整数 $T$,表示数据组数。

接下来 $T$ 行,每行两个正整数 $a,b$ 表示询问当有电的电池有 $a$ 个,没电的有 $b$ 个时,最坏情况下最少的检测次数。保证 $a \ge 2, b \ge 1$。

输出格式

共 $T$ 行,每行一个整数表示答案。

样例数据

input

3
2 1
3 1
2 2

output

3
2
6

子任务

对于全部的数据,保证 $1 \le T\le 1000, 2 \le a \le 1000, 1 \le b \le 1000$。

Subtask1 ($10\%$): $a, b \le 4$。

Subtask2 ($5\%$): $a = 2$。

Subtask3 ($10\%$): $a = 3$。

Subtask4 ($5\%$): $a > b + 1$。

Subtask5 ($20\%$): $a, b \le 10$。

Subtask6 ($30\%$): $a, b \le 30$。

Subtask7 ($20\%$): $a, b \le 1000$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.