Too Rich

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 245    Accepted Submission(s): 76

Problem Description
You are a rich person, and you think your wallet is too heavy and full now. So you want to give me some money by buying a lovely pusheen sticker which costs pdollars from me. To make your wallet lighter, you decide to pay exactly p dollars by as many coins and/or banknotes as possible.

For example, if p=17 and you have two $10 coins, four $5 coins, and eight $1 coins, you will pay it by two $5 coins and seven $1 coins. But this task is incredibly hard since you are too rich and the sticker is too expensive and pusheen is too lovely, please write a program to calculate the best solution.

 
Input
The first line contains an integer T indicating the total number of test cases. Each test case is a line with 11 integers p,c1,c5,c10,c20,c50,c100,c200,c500,c1000,c2000, specifying the price of the pusheen sticker, and the number of coins and banknotes in each denomination. The number ci means how many coins/banknotes in denominations of i dollars in your wallet.

1≤T≤20000
0≤p≤109
0≤ci≤100000

 
Output
For each test case, please output the maximum number of coins and/or banknotes he can pay for exactly p dollars in a line. If you cannot pay for exactly p dollars, please simply output '-1'.
 
Sample Input
3
17 8 4 2 0 0 0 0 0 0 0
100 99 0 0 0 0 0 0 0 0 0
2015 9 8 7 6 5 4 3 2 1 0
 
Sample Output
9
-1
36
 
Source

题意:博客吃回车,没办法。

就是说用尽量多的钞票组合成币值p,问最多用多少。

分析:

尽量用比值小的,如果先从小的开始,我们不知道小的币值能不能凑出当前所需钱数

所以从大的开始

可以发现,如果后面的钱数一共能凑出a,现在共需b,那么当前这个币值我们所需要凑出的就是(b-a),所需数量显然是max(ceil((b-a)/(当前的币值), 0)

然而,这并不是绝对的,固然,这个数量可以使后面的尽量多,但是诸如20,20,20,50这样的例子,假设b是50,那么因为a是60,导致错误,所以有可能会多用一张当前的钞票

 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name)
{
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = , Money[] = {, , , , , , , , , , };
int p, Arr[N];
LL Sum[N];
int Ans; inline void Solve(); inline void Input()
{
int TestNumber = Getint();
while(TestNumber--)
{
p = Getint();
For(i, , ) Arr[i] = Getint();
Solve();
}
} inline void Search(int Last, int x, int Cnt)
{
if(Last < ) return;
if(x < )
{
if(!Last) Ans = max(Ans, Cnt);
return;
}
LL Rest = max(Last - Sum[x - ], 0LL);
int Number = Rest / Money[x];
if(Rest % Money[x]) Number++;
if(Number <= Arr[x])
Search(Last - 1LL * Number * Money[x], x - , Cnt + Number);
if(++Number <= Arr[x])
Search(Last - 1LL * Number * Money[x], x - , Cnt + Number);
} inline void Solve()
{
Sum[] = ;
For(i, , N) Sum[i] = Sum[i - ] + 1LL * Arr[i] * Money[i];
Ans = -;
Search(p, , );
printf("%d\n", Ans);
} int main()
{
#ifndef ONLINE_JUDGE
SetIO("");
#endif
Input();
//Solve();
return ;
}

2015ACM/ICPC亚洲区长春站 A hdu 5527 Too Rich的更多相关文章

  1. 2015ACM/ICPC亚洲区长春站 L hdu 5538 House Building

    House Building Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) ...

  2. 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory

    Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  3. 2015ACM/ICPC亚洲区长春站 H hdu 5534 Partial Tree

    Partial Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)To ...

  4. 2015ACM/ICPC亚洲区长春站 G hdu 5533 Dancing Stars on Me

    Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  5. 2015ACM/ICPC亚洲区长春站 F hdu 5533 Almost Sorted Array

    Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  6. 2015ACM/ICPC亚洲区长春站 E hdu 5531 Rebuild

    Rebuild Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total S ...

  7. 2015ACM/ICPC亚洲区长春站 B hdu 5528 Count a * b

    Count a * b Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Tot ...

  8. HDU 5532 / 2015ACM/ICPC亚洲区长春站 F.Almost Sorted Array

    Almost Sorted Array Problem Description We are all familiar with sorting algorithms: quick sort, mer ...

  9. 【hdu5527】【2015ACM/ICPC亚洲区长春站 】Too Rich

    题目链接: pid=5527">http://acm.hdu.edu.cn/showproblem.php?pid=5527 题意&题解: 感觉自己真是弱啊,自己想的贪心是错的 ...

随机推荐

  1. java笔记--查看和修改线程名称

    查看和修改线程名称 --如果朋友您想转载本文章请注明转载地址"http://www.cnblogs.com/XHJT/p/3893797.html  "谢谢-- java是一种允许 ...

  2. 5 个最受人喜爱的开源 Django 包

    导读 Django 围绕“可重用应用”的思想建立:自包含的包提供了可重复使用的特性.你可以将这些可重用应用组装起来,在加上适用于你的网站的特定代码,来搭建你自己的网站.Django 具有一个丰富多样的 ...

  3. 在rails下新建表

    (文章都是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) 今天需要新建表,以下是建表语句 rails generate scaffold users ema ...

  4. django revision

    由于多次涉及到了这个东东,又不是很理解机制,决定深入研究下. what django-revision到底啥玩意?readthedocs上只有一句话概括:django-reversion can be ...

  5. php中static静态关键字的使用

    php中除了常规类和方法的使用,访问控制之外,还有静态关键字static,静态变量可以是局部变量也可以是全局变量,当一个程序段执行完毕时,静态变量并没有消失,它依然存在于内存中,下次在定义时还是以前的 ...

  6. mysql用命令行导入sql文件

    前面说到了用navicat工具导入导出数据库,今天给同事导入数据库的时候,发现到不进去,好多错误,情急之下,用命令行导入的 1.打开mysql的服务.cmd-->net start mysql ...

  7. ios学习总结(2) -- UIButton的使用

    原文地址 UIButton的类是一个UIControl子类,它实现了在触摸屏上的按钮.触摸一个按钮拦截事件和动作消息发送到目标对象时,它的挖掘.设定的目标和行动方法都继承自UIControl.这个类提 ...

  8. Step deep into GLSL

    1 Lighting computation is handled in eye space(需要根据眼睛的位置来计算镜面发射值有多少进入眼睛), hence, when using GLSL (GP ...

  9. SRAM的读写操作

    自己写的SRAM的程序,主要在于实用性,适应工作的工程需要.使用芯片为: 芯片时序图为: 代码: /********************************Copyright********* ...

  10. Oracle 日常应用和操作笔记

    简单整理oracle日常应用笔记. 1.采用excel表格中的数据直接粘贴数据库记录中,默认会在后面加一个空格“”,操作完成后一定要记得对空格匹配然后修改一下. 2.查询数据库里的所有表结构, 采用s ...