CF2232F.The Cake Is a Lie

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

To end the party, Alice decides to cook some pancakes for her friends.

Alice has nn uncooked pancakes but only 22 pans. Initially, the first min(n,2)min(n,2) pancakes are on the pans, and all pancakes have cookedness 00.

To cook her pancakes, Alice may perform the following two operations any number of times:

  • Cook the two pancakes on the pans for 11 minute. The pancake on the first pan's cookedness increases by aa, and the pancake on the second pan's cookedness increases by bb.
  • Serve the first pancake, move the second pancake to the first pan, and add a new uncooked pancake to the second pan (if there are any completely uncooked pancakes left). Note that this takes no time, and can be done multiple times in a row.

Note that if there is only one pancake left, it will be on the first pan, gaining aa cookedness per minute until Alice decides to serve it.

A pancake is perfectly cooked if and only if its cookedness is exactly kk.

Help Alice find the maximum number of perfectly cooked pancakes that she can serve.

为了结束派对,爱丽丝决定为她的朋友们做些煎饼。

爱丽丝有 nn 个未烹饪的煎饼,但只有 22 个平底锅。初始时,前 min⁡(n,2)\min(n,2) 个煎饼被放在两个平底锅上,且所有煎饼的“熟度”均为 00。

为了烹饪这些煎饼,爱丽丝可以任意次数地执行以下两种操作:

  • 将两个平底锅上的煎饼同时烹饪 11 分钟:第一个平底锅上的煎饼熟度增加 aa,第二个平底锅上的煎饼熟度增加 bb。
  • 将第一个平底锅上的煎饼端出(即服务),把第二个平底锅上的煎饼移到第一个平底锅上,并(若还有未烹饪的煎饼)将一个全新的未烹饪煎饼放入第二个平底锅。注意该操作不耗时间,且可连续多次执行。

注意:若只剩一个煎饼,则它位于第一个平底锅上,每分钟熟度增加 aa,直至爱丽丝决定将其端出。

当且仅当一个煎饼的熟度恰好等于 kk 时,它才被视为“完美烹饪”。

请帮助爱丽丝求出她最多能端出多少个“完美烹饪”的煎饼。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤10001 \le t \le 1000). The description of the test cases follows.

The only line in the test case contains 44 integers nn, aa, bb, and kk (1≤n,a,b,k≤1091 \le n,a,b,k \le 10^9) — the number of pancake batter Alice has, the amount of cookedness the pancake on the first pan gains at the end of each minute, the amount of cookedness the pancake on the second pan gains at the end of each minute, and the amount of cookedness the pancake needs to have in order for it to be perfectly cooked.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤10001 \le t \le 1000)。随后是各测试用例的描述。

每个测试用例仅有一行,包含 44 个整数 nn、aa、bb 和 kk(1≤n,a,b,k≤1091 \le n,a,b,k \le 10^9)——分别表示爱丽丝拥有的煎饼面糊份数、第一个平底锅上的煎饼每分钟末增加的熟度值、第二个平底锅上的煎饼每分钟末增加的熟度值,以及煎饼达到完美熟度所需的熟度值。

输出格式

For each test case, output the maximum number of perfectly cooked pancakes Alice can make.

对于每个测试用例,输出 Alice 能制作的完美煎饼的最大数量。

输入输出样例

  • 输入#1

    7
    17 1 1 1
    123456789 987 654 321
    3 11 37 111111
    987654321 1 2 123456789
    100 1 2 1
    100 1 2 2
    1 1 1 1

    输出#1

    17
    0
    2
    987654320
    50
    67
    1

说明/提示

In the first testcase, Alice can perfectly cook all pancakes in a batch of two. Therefore, the maximum number of perfectly cooked pancakes is 1717.

In the second test case, Alice will always overcook all pancakes since both pans are too hot. Therefore, the maximum number of perfectly cooked pancakes is 00.

In the third test case, Alice can leave the first two pancakes on the pans for 30033003 minutes, then serve both of them, one undercooked and one perfectly cooked. For the last pancake, she leaves it on the pan for 10 10110\,101 minutes before serving it to make it perfectly cooked. Since there are no ways to perfectly cook the first two pancakes (by the time the first pancake is perfectly cooked, the second pancake will be overcooked), the maximum number of perfectly cooked pancakes is 22.

在第一个测试用例中,Alice 可以恰好将所有煎饼以每批两个的方式完美烹制。因此,完美烹制的煎饼最大数量为 1717。

在第二个测试用例中,由于两个平底锅温度均过高,Alice 总是会将所有煎饼烹制过头。因此,完美烹制的煎饼最大数量为 00。

在第三个测试用例中,Alice 可将前两个煎饼留在平底锅上 30033003 分钟,然后同时端出——其中一个烹制不足,另一个恰好完美烹制;对于最后一个煎饼,她将其留在平底锅上 10 10110\,101 分钟后再端出,使其恰好完美烹制。由于不存在一种方式能同时使前两个煎饼都完美烹制(当第一个煎饼恰好完美烹制时,第二个煎饼必然已烹制过头),因此完美烹制的煎饼最大数量为 22。

输入解题思路,AI测评打分。不知道怎么写?

首页