BestCoder Round #84 1001 hdu 5747 模拟
来源:互联网 发布:淘宝宝贝链接怎么发 编辑:程序博客网 时间:2024/04/30 08:02
链接:戳这里
Aaronson
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
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
思路:
直接将n去填(1<<i)就可以了 ,还有就是m不能超过32
代码:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<vector>#include <ctime>#include<queue>#include<set>#include<map>#include<stack>#include<iomanip>#include<cmath>#define mst(ss,b) memset((ss),(b),sizeof(ss))#define maxn 0x3f3f3f3f#define MAX 1000100///#pragma comment(linker, "/STACK:102400000,102400000")typedef long long ll;typedef unsigned long long ull;#define INF (1ll<<60)-1using namespace std;int a[33];int n,m;int main(){ for(int i=0;i<=30;i++) a[i]=(1<<i); int T; scanf("%d",&T); while(T--){ scanf("%d%d",&n,&m); int x=lower_bound(a,a+30,n)-a; int ans=0; for(int i=min(m,x);i>=0;i--){ ans=ans+n/a[i]; n%=a[i]; if(n==0) break; } printf("%d\n",ans); } return 0;}
0 0
- BestCoder Round #84 1001 hdu 5747 模拟
- HDU 5747 BestCoder Round #84 Aaronson (模拟)
- hdu 5747 Aaronson (BestCoder Round #84 1001)
- BestCoder Round #64 (div.2) 1001 Numbers HDU 5585 模拟
- BestCoder Round #75 1001模拟
- HDU BestCoder Round #48 1001
- HDU 5777 BestCoder Round #85 domino (多米诺骨牌模拟)
- BestCoder Round #84 1004 hdu 5750 数论
- BestCoder round#3 1001 && Hdu 4907
- hdu 4989 Summary(BestCoder Round #8 1001)
- BestCoder Round #16 1001(hdu 5086)
- HDU 5280 BestCoder Round#47 1001
- BestCoder Round #49 ($) HDU 5339 Untitled(1001)
- BestCoder Round #75 1002模拟
- BestCoder Round #59 (div.2) 1001 SDOI 模拟题
- hdu 5641 BestCoder Round #75
- hdu 5643 BestCoder Round #75
- BestCoder Round #83(HDU 5680)
- Android执行定时循环任务
- 缓存-redis
- 8086汇编语言 汇编源程序中使用jmp命令修改IP
- 8086汇编语言 汇编源程序中使用jmp命令修改CS:IP
- CSS3样式二
- BestCoder Round #84 1001 hdu 5747 模拟
- VO PO BO QO DAO POJO慨念
- Github搭建过程简记
- js的call和apply函数的使用
- 3.3 从标准输入读入一个数,把它转为英语单词输出,如读入 234,输出“two three four”。
- event面向对象【笔记-未完】
- Openstack Gnocchi 笔记
- 3.4 编写一个程序,将用户输入的数字(0~6)转换成相应的星期值输出。如用户输 入 3,则程序输出“Today is Wed”;用户输入 0,则输出“Today is Sun”。如果用户输入 的数据
- BestCoder Round #84 1002 hdu 5748 最长上升子序列