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. kubeadm安装k8s1.13

    1.环境介绍: centos 7.4.1708 关闭selinux和iptable,环境很重要! 主机 ip地址 cpu核数 内存 swap host解析 k8s-master 10.0.0.11 2 ...

  2. openxlsx模块

    import openpyxl #创建工作簿 wb = openpyxl.Workbook()#获取当前活跃的工作表 ws = wb.active#删除工作表 remove_sheet(wb.get_ ...

  3. svn 权限设置

    /***********************************************************/ //SVNSubversion 用户权限管理 //资料来源:网络.总结 // ...

  4. jaxb解析xml工具类

    [quote]jaxb jdk 自带的解析xml的一种方式支持,只需要用注解对javabean进行数据绑定[/quote] package com.nnk.flowrecharge.common;im ...

  5. python中import cv2遇到的错误及安装方法

    参考链接:https://blog.csdn.net/yuanlulu/article/details/79017116 从x86_64 + ubuntu18.04 + python3.5中impor ...

  6. l洛谷P4779 【模板】单源最短路径(标准版)(dijkstra)

    题目描述 给定一个 NN 个点,MM 条有向边的带非负权图,请你计算从 SS 出发,到每个点的距离. 数据保证你能从 SS 出发到任意点. 输入格式 第一行为三个正整数 N, M, SN,M,S. 第 ...

  7. anaconda安装失败

    2019.10版本怎么安装都不行换了2018.10安装ok

  8. PHP循环while do while循环

    <?php #从1打印到10,除了5 $i=1; while ($i<10) { if ($i==5) { $i++; continue; } echo $i++."<br ...

  9. JZOJ5373【NOIP2017提高A组模拟9.17】信仰是为了虚无之人

    题目 分析 我们发现,如果[l,r]的异或和为k是真要求,有且仅当不存在[l,i]和[i,r]两个区间的异或和不为k. 我们用带权并查集了维护这些,但是,由于区间不连续,我们将点权移到边上,对于区间[ ...

  10. Harbor ($docker login) Error saving credentials

    $ sudo apt-get install $ sudo apt-get install gnupg2 pass 问题解决!