CF1578E.Easy Scheduling

普及-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

Eonathan Eostar decided to learn the magic of multiprocessor systems. He has a full binary tree of tasks with height hh. In the beginning, there is only one ready task in the tree — the task in the root. At each moment of time, pp processes choose at most pp ready tasks and perform them. After that, tasks whose parents were performed become ready for the next moment of time. Once the task becomes ready, it stays ready until it is performed.

You shall calculate the smallest number of time moments the system needs to perform all the tasks.

伊奥纳坦·伊奥斯塔尔决定学习多处理器系统的魔法。他有一棵高度为 hh 的满二叉树形式的任务树。初始时,树中只有一个就绪任务——即根节点处的任务。在每一时刻,pp 个处理器最多选择 pp 个就绪任务并执行它们。执行完毕后,那些父任务已被执行的任务将在下一时刻变为就绪状态。一个任务一旦变为就绪状态,便会一直保持就绪状态,直至被执行。

你需要计算系统执行完所有任务所需的最少时间时刻数。

输入格式

The first line of the input contains the number of tests tt (1≤t≤5⋅1051 \leq t \leq 5\cdot 10^5). Each of the next tt lines contains the description of a test. A test is described by two integers hh (1≤h≤501 \leq h \leq 50) and pp (1≤p≤1041 \leq p \leq 10^4) — the height of the full binary tree and the number of processes. It is guaranteed that all the tests are different.

输入的第一行包含测试用例的数量 tt(1≤t≤5⋅1051 \leq t \leq 5\cdot 10^5)。接下来的 tt 行每行描述一个测试用例。每个测试用例由两个整数 hh(1≤h≤501 \leq h \leq 50)和 pp(1≤p≤1041 \leq p \leq 10^4)描述,分别表示满二叉树的高度和进程数量。保证所有测试用例互不相同。

输出格式

For each test output one integer on a separate line — the smallest number of time moments the system needs to perform all the tasks.

对于每组测试数据,输出一行一个整数——系统完成所有任务所需的最少时间点数量。

输入输出样例

  • 输入#1

    3
    3 1
    3 2
    10 6

    输出#1

    7
    4
    173

说明/提示

Let us consider the second test from the sample input. There is a full binary tree of height 33 and there are two processes. At the first moment of time, there is only one ready task, 11, and p1p_1 performs it. At the second moment of time, there are two ready tasks, 22 and 33, and the processes perform them. At the third moment of time, there are four ready tasks, 44, 55, 66, and 77, and p1p_1 performs 66 and p2p_2 performs 55. At the fourth moment of time, there are two ready tasks, 44 and 77, and the processes perform them. Thus, the system spends 44 moments of time to perform all the tasks.

我们考虑样例输入中的第二个测试用例。该测试用例对应一棵高度为 33 的满二叉树,且有两个进程。在第一个时间点,仅有一个就绪任务 11,由进程 p1p_1 执行。在第二个时间点,有两个就绪任务 22 和 33,两个进程分别执行它们。在第三个时间点,有四个就绪任务 44、55、66 和 77,其中 p1p_1 执行任务 66,p2p_2 执行任务 55。在第四个时间点,有两个就绪任务 44 和 77,两个进程分别执行它们。因此,系统共花费 44 个时间点来完成所有任务。

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

首页