HDU 5747 BestCoder Round #84 Aaronson (模拟)

来源:互联网 发布:淘宝客服接待流程 编辑:程序博客网 时间:2024/04/30 22:09

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 equationx0+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 (0im) is non-negative.
Input
There are multiple test cases. The first line of input contains an integerT(1T105), indicating the number of test cases. For each test case:
The first contains two integers n and m(0n,m109).
Output
For each test case, output the minimum value ofi=0mxi.
Sample Input
101 23 25 210 210 310 413 520 411 1112 3
Sample Output
1223223232
Source
BestCoder Round #84
Recommend
wange2014   |   We have carefully selected several similar problems for you:  5751 5750 5749 5748 5746 

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

AC代码:
//#include<bits/stdc++.h>#include<iostream>#include<stdio.h>#include<cstring>#include<algorithm>using 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;}


 
1 0
原创粉丝点击