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

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

题目出处:中文翻译

从2的最大次幂开始除以保证最终得数最小。

附AC代码:

 #include<iostream>
#include<cmath>
using namespace std; /*
int Pow(int a,int b){
int temp=1;
for(int i=0;i<b;i++){
temp*=a;
}
return temp;
}
*/ int main(){
int t,m,n,k,sum;
cin>>t;
int s[];
s[]=;
for(int i=;i<;i++){//打表
s[i]=s[i-]+s[i-];
}
while(t--){
cin>>n>>m;
sum=;
for(int j=min(m,);j>=;j--) //当n可被除时,从最大2的最大次幂开始除以保证结果最小
if(n>=s[j])
{
k=n/s[j];
sum+=k;
n-=k*s[j];
}
cout<<sum<<endl;
}
return ;
}

Aaronson的更多相关文章

  1. BestCoder Round #84 Aaronson

    Aaronson 题意: 给个中文链接:戳戳戳 题解: 这题一看给的公式就是二进制,之后马上就能想到当m大于等于二进制的位数时,输出n的二进制的1的个数就好了.之后就是m小于二进制的位数时,只要加上2 ...

  2. hdu-5747 Aaronson(水题)

    题目链接: Aaronson Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 131072/131072 K (Java/Others ...

  3. hdu5747 Aaronson 贪心

    Aaronson Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  4. hdu 5747 Aaronson

    T :  1 n m:  10  2 题解:20 * 0  +  21* 1  +  22* 2 = 10 输出:3  <--  0+1+2=3 AC 代码: #include<stdio ...

  5. Aaronson,又是思维题

    题目: Recently, Peter saw the equation x0+2x1+4x2+...+2mxm=nx0+2x1+4x2+...+2mxm=n. He wants to find a ...

  6. 【贪心算法】HDU 5747 Aaronson

    题目大意 vjudge链接 给你一个n,m,求解满足等式x0+2x1+4x2+...+2mxm=n的x0~xm的最小和(xi为非负整数) 数据范围 0≤n,m≤109 思路 n和m都在int范围内,所 ...

  7. Bestcoder Round #84

    A题 Aaronson http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=718&pid=1001 感觉一 ...

  8. 套题 bestcoder 84

    A题:Aaronson 静下心来观察就会发现1.如果m大于等于n的位数,那么n直接写成二进制形式就是最优解形式2.如果m小于n的位数,那么贪心地使得高位尽可能地多消掉n的值,因为高位少写一个数就意味着 ...

  9. 证明与计算(1): Decision Problem, Formal Language L, P and NP

    0x01 从判定问题到形式语言 这篇讲知识证明的wiki([1]): https://en.wikipedia.org/wiki/Proof_of_knowledge 里面有一句话: Let x be ...

随机推荐

  1. H5实现多图片预览上传,可点击可拖拽控件介绍

    版权声明:欢迎转载,请注明出处:http://blog.csdn.net/weixin_36380516 在做图片上传时发现一个蛮好用的控件,支持多张图片同时上传,可以点击选择图片,也可以将图片拖拽到 ...

  2. Python+Selenium框架-unittest执行脚本方法之addTest

    本文开始介绍如何通过unittest来管理和执行测试用例,这一篇介绍unittest下addTest()方法来加载测试用例到测试套件中去.为了演示效果,我在前面文章的脚本基础上,新建了一个测试脚本,这 ...

  3. 零基础学python-3.1 python基本规则和语句

    1."#"凝视的開始 #凝视的东西 print("welcome") 2."\n"换行符 watermark/2/text/aHR0cDov ...

  4. POJ 3580(SuperMemo-Splay区间加)[template:Splay V2]

    SuperMemo Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 11384   Accepted: 3572 Case T ...

  5. poj3181 Dollar Dayz

    Description Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of to ...

  6. css-装饰

    css -在标签上设置style样式 background-color:#2356a1 height:48px -编写样式方法 1.标签的style属性 2.鞋子head里面,style标签中编写 - ...

  7. webstorm 设置IP 访问 手机测试效果

    http://www.cnblogs.com/gulei/p/5126383.html 前端开发中,经常需要将做好的页面给其他同事预览或手机测试,之前一直用的第三方本地服务器usbwebserver, ...

  8. 利用crtmpserver搭建rtmp服务器

    Google + 实践:最终直播成功. 记录一下. 这样.兴许就能够对代码进行改造,利用开源码实现:Android平台下.搭建rtmpserver.浏览器端利用flash播放视频. 代码架构为:ffm ...

  9. c++的运算符的重载

    1 什么是c++运算符的重载 c++运算符的重载就是说对+.-.>.<等运算符进行重新定义,这样的话,除了基本的类型,所有的类都可以进行基本的运算了,用起来非常方便.特别是用在各种算法中. ...

  10. Protocol_BGP

    BGP协议 作者:Danbo 2015-7-8 BPG最重要的就是属性,下面我们针对路径属性分析一下.