CF2173D.Taiga's Carry Chains
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Miracles don't happen to those who just wait.
— Toradora!
After classes at Ohashi High School, Ryuuji hands Taiga a positive integer n and sets a simple challenge.
They will play for exactly k moves. In a single move, Taiga chooses a non-negative integer ℓ and sets n←n+2ℓ.
Ryuuji defines the score of one move as the number of binary carries that occur when adding 2ℓ to the current number in base 2. The total score is the sum of score over all k moves.
Taiga wants the total score to be as large as possible after k moves. What is the maximum total score she can achieve?
奇迹不会眷顾那些只会等待的人。
——《龙与虎》!
在大桥高中的课程结束后,龙儿交给大河一个正整数 n,并设下了一个简单的挑战。
他们将恰好进行 k 轮操作。在每一轮中,大河选择一个非负整数 ℓ,并将 n 更新为 n←n+2ℓ。
龙儿将单轮操作的“得分”定义为:在二进制下将 2ℓ 加到当前数字时所发生的进位次数。总得分为 k 轮操作得分之和。
大河希望经过 k 轮操作后,总得分尽可能大。她所能达到的最大总得分是多少?
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤1000). The description of the test cases follows.
The only line of each test case contains two integers n and k (1≤n<230, 0≤k≤109) — the initial integer and the number of moves.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤1000)。随后是各测试用例的描述。
每个测试用例仅有一行,包含两个整数 n 和 k(1≤n<230,0≤k≤109)——分别表示初始整数和操作次数。
输出格式
For each test case, output a single integer — the maximum total score that Taiga can achieve.
对于每个测试用例,输出一个整数——即太郎所能获得的最高总分。
输入输出样例
输入#1
6 7 1 13 2 42 2 1048576 100 23 2 371 1
输出#1
3 4 3 100 5 3
说明/提示
In the first test case, (n,k)=(7,1) and 7=1112. Adding 20 gives 111+1=1000, which produces carries at bits 0,1,2. So the total score is 3.
In the second test case, (n,k)=(13,2) with 13=11012. First we add 20: 1101+0001=1110, which creates one carry. Then we add 21: 1110+0010=10000, with carries propagating through bits 1,2,3. In total there are 1+3=4 carries, so the score is 4.
In the third test case, (n,k)=(42,2) and 42=1010102. First we add 21: 101010+000010=101100, giving one carry. Next we add 22: 101100+000100=110000, which generates carries at bits 2 and 3. Thus the total number of carries is 1+2=3.
In the fifth test case, (n,k)=(23,2) and 23=101112. First we add 20: 10111+00001=11000, which produces carries at bits 0,1,2. Then we add 23: 11000+01000=100000, producing carries at bits 3 and 4. Altogether there are 3+2=5 carries, so the total score is 5.
在第一个测试用例中,(n,k)=(7,1),且 7=1112。加上 20 得到 111+1=1000,该加法在二进制位 0,1,2 上均产生进位。因此总得分为 3。
在第二个测试用例中,(n,k)=(13,2),且 13=11012。首先加上 20:1101+0001=1110,产生一次进位;接着加上 21:1110+0010=10000,进位传播经过二进制位 1,2,3。总共发生 1+3=4 次进位,因此得分为 4。
在第三个测试用例中,(n,k)=(42,2),且 42=1010102。首先加上 21:101010+000010=101100,产生一次进位;接着加上 22:101100+000100=110000,在二进制位 2 和 3 上产生进位。因此进位总数为 1+2=3。
在第五个测试用例中,(n,k)=(23,2),且 23=101112。首先加上 20:10111+00001=11000,在二进制位 0,1,2 上产生进位;接着加上 23:11000+01000=100000,在二进制位 3 和 4 上产生进位。总共发生 3+2=5 次进位,因此总得分为 5。
输入解题思路,AI测评打分。不知道怎么写?