Aaronson
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 231 Accepted Submission(s): 149Problem DescriptionRecently, 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.InputThere 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).
OutputFor each test case, output the minimum value of ∑i=0mxi.Sample Input10
1 2
3 2
5 2
10 2
10 3
10 4
13 5
20 4
11 11
12 3Sample Output1
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的更多相关文章
- BestCoder Round #84 Aaronson
Aaronson 题意: 给个中文链接:戳戳戳 题解: 这题一看给的公式就是二进制,之后马上就能想到当m大于等于二进制的位数时,输出n的二进制的1的个数就好了.之后就是m小于二进制的位数时,只要加上2 ...
- hdu-5747 Aaronson(水题)
题目链接: Aaronson Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- hdu5747 Aaronson 贪心
Aaronson Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- hdu 5747 Aaronson
T : 1 n m: 10 2 题解:20 * 0 + 21* 1 + 22* 2 = 10 输出:3 <-- 0+1+2=3 AC 代码: #include<stdio ...
- Aaronson,又是思维题
题目: Recently, Peter saw the equation x0+2x1+4x2+...+2mxm=nx0+2x1+4x2+...+2mxm=n. He wants to find a ...
- 【贪心算法】HDU 5747 Aaronson
题目大意 vjudge链接 给你一个n,m,求解满足等式x0+2x1+4x2+...+2mxm=n的x0~xm的最小和(xi为非负整数) 数据范围 0≤n,m≤109 思路 n和m都在int范围内,所 ...
- Bestcoder Round #84
A题 Aaronson http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=718&pid=1001 感觉一 ...
- 套题 bestcoder 84
A题:Aaronson 静下心来观察就会发现1.如果m大于等于n的位数,那么n直接写成二进制形式就是最优解形式2.如果m小于n的位数,那么贪心地使得高位尽可能地多消掉n的值,因为高位少写一个数就意味着 ...
- 证明与计算(1): Decision Problem, Formal Language L, P and NP
0x01 从判定问题到形式语言 这篇讲知识证明的wiki([1]): https://en.wikipedia.org/wiki/Proof_of_knowledge 里面有一句话: Let x be ...
随机推荐
- 零基础学python-3.1 python基本规则和语句
1."#"凝视的開始 #凝视的东西 print("welcome") 2."\n"换行符 watermark/2/text/aHR0cDov ...
- 【课程笔记】比特币和数字货币技术[Bitcoin and Cryptocurrency Technologies] week1
源地址(可能要FQ):https://www.coursera.org/learn/cryptocurrency/home/welcome 1.1 Cryptographic Hash Functio ...
- 分布式开源调度框架TBSchedule原理与应用
主要内容: 第一部分 TBSchedule基本概念及原理 1. 概念介绍 2. 工作原理 3. 源代码分析 4. 与其它开源调度框架对照 第二部分 TBSchedule分布式调度演示样例 1. TBS ...
- Webkit JNI
WebCoreFrameBridge.cpp BrowserFrame通过jni传下来的调用都会调用到WebCoreFrameBridge.cpp中的对应函数中,其他webkit的模块想回调信息给Br ...
- EasyDarwin云平台:EasyCamera开源摄像机接入海康威视摄像机PS流转ES流
本文转自EasyDarwin开源团队成员Alex的博客:http://blog.csdn.net/cai6811376 海康威视使用PS流封装H.264流,EasyDarwin云平台支持ES流.当我们 ...
- linux socket send和recv、write和read
1 recv和read ssize_t recv(int sockfd, void *buf, size_t len, int flags); ssize_t read(int fd, void *b ...
- csslint
http://csslint.net/ line column title description browserwarning 1 1 Disallow @import @import preven ...
- Running several name-based web sites on a single IP address.
VirtualHost Examples - Apache HTTP Server Version 2.2 http://httpd.apache.org/docs/2.2/vhosts/exampl ...
- r squared
multiple r squared adjusted r squared http://web.maths.unsw.edu.au/~adelle/Garvan/Assays/GoodnessOfF ...
- React深入源码--了解Redux用法之Provider
在Redux中最核心的自然是组件,以及组件相关的事件与数据流方式.但是我们在Redux中并没有采用传统的方式在getInitialState()中去初始化数据,而是采用Provider统一处理,省去了 ...