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. C# Select SelectMany 区别

    string[] text = { "Today is 2018-06-06", "weather is sunny", "I am happy&qu ...

  2. 日志打印longging模块(控制台和文件同时输出)

    在把日志写入文件的同时在控制台输出 示例代码如下: #coding=utf-8 import logging import time import os dir = os.path.dirname(o ...

  3. 做QA的日子——iOS測试入门(四)

    坦言,做QA的这半年我没有成长,就算有成长也非常少,我非常难过.和身边的人讲事实上并没有谁能真正理解自己的难过,事实上还是自己不够努力.对自己不够狠,以前认为自己不够幸运,想有一个更好的指路人,事实上 ...

  4. vmware安装操作系统

    安装的时候,直接选择“从光盘或者映像安装”就可以了,很方便的.不需要再去从u盘什么的安装了.

  5. 无感知的用同步的代码编写方式达到异步IO的效果和性能,避免了传统异步回调所带来的离散的代码逻辑和陷入多层回调中导致代码无法维护

    golang/goroutine 和 swoole/coroutine 协程性能测试对比 - Go语言中文网 - Golang中文社区 https://studygolang.com/articles ...

  6. Javascript学习之Function对象详解

    JavaScript中的Function对象,就是我们常说的函数对象.在JS中,所有的函数也是以对象的形式存在的. 语法 充当Function对象的构造函数使用,用于结合new关键字构造一个新的Fun ...

  7. 20170316 ABAP注意点

    1.debug 时在MODIFY db from table 后数据便提交了: 一般情况下,更新数据库需要commit,但debug会自动commit,程序结束也会自动commit. 2.使用at n ...

  8. matlab面向对象设计---类的概念和使用

    代码: classdef MadgwickAHRS < handle %MADGWICKAHRS Implementation of Madgwick's IMU and AHRS algori ...

  9. PAT 天梯赛 L2-008. 最长对称子串 【字符串】

    题目链接 https://www.patest.cn/contests/gplt/L2-008 思路 有两种思路 第一种 遍历每一个字符 然后对于每一个 字符 同时 往左 和 往右 遍历 只要 此时 ...

  10. Codeforces Round #376 (Div. 2) A. Night at the Museum —— 循环轴

    题目链接: http://codeforces.com/contest/731/problem/A A. Night at the Museum time limit per test 1 secon ...