HDU 5747 BestCoder Round #84 Aaronson (模拟)

网友投稿 747 2022-08-23

HDU 5747 BestCoder Round #84 Aaronson (模拟)

HDU 5747 BestCoder Round #84  Aaronson (模拟)

Aaronson

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 346    Accepted Submission(s): 210

Problem Description

Recently, Peter saw the equation x0+2x1+4x2+...+2mxm=n. He wants to find a solution (x0,x1,x2,...,xm) in such a manner that ∑i=0mxi is minimum and every xi (0≤i≤m) is non-negative.

Input

There are multiple test cases. The first line of input contains an integer T (1≤T≤105), indicating the number of test cases. For each test case: The first contains two integers n and m (0≤n,m≤109).

Output

For each test case, output the minimum value of ∑i=0mxi.

Sample Input

10 1 2 3 2 5 2 10 2 10 3 10 4 13 5 20 4 11 11 12 3

Sample Output

1 2 2 3 2 2 3 2 3 2

Source

​​BestCoder Round #84​​

Recommend

wange2014   |   We have carefully selected several similar problems for you:  ​​5751​​​ ​​5750​​​ ​​5749​​​ ​​5748​​​ ​​5746​​

题解:模拟一下就好了。。。

AC代码:

//#include#include#include#include#includeusing namespace std;int main(){ int t; scanf("%d",&t); while(t--) { int n,m; scanf("%d%d",&n,&m); int ans=0; int d =1 <<(min(m,30)); while(n) { ans+=n/d; n-=n/d*d; d/=2; } printf("%d\n",ans); } return 0;}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:常用的svn和git命令(Git和SVN)
下一篇:HDU 2114 Calculate S(n)(立方阶求和公式)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~