当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3586:The missionaries and cannibals

题目描述

The missionaries and cannibals problem is usually stated as follows: Three missionaries and three cannibals are on one side of a river, along with a boat that can hold one or two people. Find a way to get everyone to the other side, without ever leaving a group of missionaries in one place outnumbered by the cannibals in that place. Now the problem has been extended to be more complicated. There are m missionaries and m cannibals who want to cross the river. And the boat is also enlarged to be capable of supporting n people. In order to make all of them cross the river safely what is the least number of steps? Notice that when the boat goes across the river there must be at least one missionary or cannibal on the boat.

输入解释

The first line of the input is an integer T which indicates the number of test cases. Each test case is specified on a separate line and is made of two positive number m and n, where m ≤ 100000 and n ≤ 1000.

输出解释

For each test case, output the result on a single line. If the problem can't be solved, print -1 as the result.
 

输入样例
2
3 2
20 3
输出样例
11
-1

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3586

最后修改于 2020-10-29T07:05:17+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
10000 65536