Aaronson

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

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
#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>
using namespace std;
int main(){
int t;
int a[];
for(int i=;i<;i++){
a[i]=(<<i);
}
scanf("%d",&t);
while(t--){
int n,m;
int ans=;
scanf("%d%d",&n,&m);
int x =lower_bound(a,a+,n)-a;
for(int i=min(x,m);i>=;i--){ ans+=(n/a[i]);
n%=a[i];
if(n==) break;
}
printf("%d\n",ans);
}
return ;
}

hdu5747 Aaronson 贪心的更多相关文章

  1. hdu-5747 Aaronson(水题)

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

  2. 【贪心算法】HDU 5747 Aaronson

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

  3. hdu 5747(数学,贪心)

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

  4. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  5. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  6. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]

    1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 786  Solved: 391[Submit][S ...

  8. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  9. 【BZOJ-4245】OR-XOR 按位贪心

    4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 486  Solved: 266[Submit][Sta ...

随机推荐

  1. AngularJs 初级入门 学习笔记

    刚学angular, 做一些笔记方便自己翻看. ng-app: 填写模块的名称 ng-init: 初始化数据(一般通过控制器初始化) ng-model: 填写数据模型 ng-bind: 绑定数据模型, ...

  2. MyCat配置简述以及mycat全局ID

    Mycat可以直接下载解压,简单配置后可以使用,主要配置项如下: 1. log4j2.xml:配置MyCat日志,包括位置,格式,单个文件大小 2. rule.xml: 配置分片规则 3. schem ...

  3. 配置Linux静态IP地址

  4. Ext4文件系统修复

    Ext4文件系统修复 目录 一. super block........................................................................ ...

  5. Python基础编程:字符编码、数据类型、列表

    目录: python简介 字符编码介绍 数据类型 一.Python简介 Python的创始人为Guido van Rossum.1989年圣诞节期间,在阿姆斯特丹,Guido为了打发圣诞节的无趣,决心 ...

  6. js事件总汇

    Mouse 事件 描述onClick                     鼠标点击事件,多用在某个对象控制的范围内的鼠标点击 onDblClick                鼠标双击事件 on ...

  7. 团队作业-Beta冲刺(周四)

    一. 这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1/ 这个作业要求在哪里 https://edu.c ...

  8. vps 11步移站步骤笔记

    移站是经常的事,现在把步骤写上,防止忘记命令 1.登录SSH 2.打包数据库,phpmyadmin中备份数据库,导入新数据库,数据库中域名链接进行相应替换 获取phpmyadmin root密码 ca ...

  9. zencart模板列表下载地址

    下载index.html文件后用浏览器打开,里面有一百多个zencart模板示例 下载地址:zencart模板示例下载地址 或者复制下面网址,用浏览器打开即可下载: http://bcs.duapp. ...

  10. C++类模板——博客链接

    https://www.jianshu.com/p/70ca94872418 C++类模板,你看我就够了 值得学习~