天天看点

HDU 5747 BestCoder Round #84 Aaronson (模拟)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 x

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson
HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

+2x

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

1

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

+4x

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

2

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

+...+2

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

m

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

x

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

m

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

=n

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

. He wants to find a solution (x

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson
HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

,x

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

1

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

,x

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

2

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

,...,x

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

m

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

)

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

in such a manner that ∑

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

i=0

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

m

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

x

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

i

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson
HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

is minimum and every x

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

i

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson
HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

( 0≤i≤m

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

) is non-negative. Input There are multiple test cases. The first line of input contains an integer T

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

(1≤T≤10

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

5

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

)

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

, indicating the number of test cases. For each test case:

The first contains two integers n

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

and m

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

(0≤n,m≤10

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

9

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

)

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

. Output For each test case, output the minimum value of ∑

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

i=0

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

m

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

x

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

i

HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson
HDU 5747 BestCoder Round #84 Aaronson (模拟)Aaronson

. 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<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;
}