CF1895A.Treasure Chest
入门
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Monocarp has found a treasure map. The map represents the treasure location as an OX axis. Monocarp is at 0, the treasure chest is at x, the key to the chest is at y.
Obviously, Monocarp wants to open the chest. He can perform the following actions:
- go 1 to the left or 1 to the right (spending 1 second);
- pick the key or the chest up if he is in the same point as that object (spending 0 seconds);
- put the chest down in his current point (spending 0 seconds);
- open the chest if he's in the same point as the chest and has picked the key up (spending 0 seconds).
Monocarp can carry the chest, but the chest is pretty heavy. He knows that he can carry it for at most k seconds in total (putting it down and picking it back up doesn't reset his stamina).
What's the smallest time required for Monocarp to open the chest?
莫诺卡普发现了一张藏宝图。该地图将宝藏位置表示为一条 OX 轴:莫诺卡普位于 0,宝箱位于 x,开启宝箱的钥匙位于 y。
显然,莫诺卡普希望打开宝箱。他可以执行以下操作:
- 向左或向右移动 1 单位(耗时 1 秒);
- 若他与钥匙或宝箱处于同一位置,则可拾取该物品(耗时 0 秒);
- 将宝箱放置于他当前所在位置(耗时 0 秒);
- 若他与宝箱处于同一位置且已拾取钥匙,则可打开宝箱(耗时 0 秒)。
莫诺卡普可以携带宝箱,但宝箱非常沉重。他知道自己最多只能连续携带宝箱 k 秒(放下宝箱再重新拾起不会重置他的体力)。
请问莫诺卡普打开宝箱所需的最短时间是多少?
输入格式
The first line contains a single integer t (1≤t≤100) — the number of testcases.
The only line of each testcase contains three integers x,y and k (1≤x,y≤100; x=y; 0≤k≤100) — the initial point of the chest, the point where the key is located, and the maximum time Monocarp can carry the chest for.
第一行包含一个整数 t(1≤t≤100)—— 测试用例的数量。
每个测试用例仅有一行,包含三个整数 x,y 和 k(1≤x,y≤100;x=y;0≤k≤100)—— 分别表示宝箱的初始位置、钥匙所在的位置,以及 Monocarp 最多能携带宝箱的时间。
输出格式
For each testcase, print a single integer — the smallest time required for Monocarp to open the chest.
对于每个测试用例,输出一个整数——Monocarp 打开宝箱所需的最短时间。
输入输出样例
输入#1
3 5 7 2 10 5 0 5 8 2
输出#1
7 10 9
说明/提示
In the first testcase, Monocarp can open the chest in 7 seconds with the following sequence of moves:
- go 5 times to the right (5 seconds);
- pick up the chest (0 seconds);
- go 2 times to the right (2 seconds);
- pick up the key (0 seconds);
- put the chest down (0 seconds);
- open the chest (0 seconds).
He only carries the chest for 2 seconds, which he has the stamina for.
In the second testcase, Monocarp can pick up the key on his way to the chest.
In the third testcase, Monocarp can't use the strategy from the first testcase because he would have to carry the chest for 3 seconds, while he only has the stamina for 2 seconds. Thus, he carries the chest to 7, puts it down, moves 1 to the right to pick up the key and returns 1 left to open the chest.
在第一个测试用例中,Monocarp 可以通过以下操作序列在 7 秒内打开宝箱:
- 向右移动 5 次(耗时 5 秒);
- 拾起宝箱(耗时 0 秒);
- 向右移动 2 次(耗时 2 秒);
- 拾起钥匙(耗时 0 秒);
- 放下宝箱(耗时 0 秒);
- 打开宝箱(耗时 0 秒)。
他仅需携带宝箱 2 秒,这在其体力承受范围内。
在第二个测试用例中,Monocarp 可以在前往宝箱的途中拾取钥匙。
在第三个测试用例中,Monocarp 无法采用第一个测试用例中的策略,因为该策略要求他携带宝箱 3 秒,而他仅有 2 秒的体力。因此,他先将宝箱携带至位置 7 并放下,再向右移动 1 单位拾取钥匙,最后向左返回 1 单位打开宝箱。
输入解题思路,AI测评打分。不知道怎么写?