2015ACM/ICPC亚洲区长春站 A hdu 5527 Too Rich
Too Rich
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 245 Accepted Submission(s): 76
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.
1≤T≤20000
0≤p≤109
0≤ci≤100000
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
-1
36
题意:博客吃回车,没办法。
就是说用尽量多的钞票组合成币值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的更多相关文章
- 2015ACM/ICPC亚洲区长春站 L hdu 5538 House Building
House Building Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) ...
- 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- 2015ACM/ICPC亚洲区长春站 H hdu 5534 Partial Tree
Partial Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)To ...
- 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 ...
- 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 ...
- 2015ACM/ICPC亚洲区长春站 E hdu 5531 Rebuild
Rebuild Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total S ...
- 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 ...
- HDU 5532 / 2015ACM/ICPC亚洲区长春站 F.Almost Sorted Array
Almost Sorted Array Problem Description We are all familiar with sorting algorithms: quick sort, mer ...
- 【hdu5527】【2015ACM/ICPC亚洲区长春站 】Too Rich
题目链接: pid=5527">http://acm.hdu.edu.cn/showproblem.php?pid=5527 题意&题解: 感觉自己真是弱啊,自己想的贪心是错的 ...
随机推荐
- sql把表格拼成字符串,多半使用于GROUP BY
--假定要聚合的字段是id ,要统计的字段是tname --select a.tname from @T1 a for xml path('row') select id,REPLACE(replac ...
- Mysql limit offset
Mysql limit offset 假设数据库表student存在13条数据. 语句1:select * from student limit 9,4 语句2:slect * from studen ...
- django 1.5+ 权限设计浅析
权限关系图 依赖app: django.contrib.auth django.contrib.contenttype admin后台的权限控制解析 (path/to/django.contrib.a ...
- raw格式镜像文件压缩并转换为qcow2格式
raw格式文件,这个比较占用空间,你可以用以下命令将其压缩并转换成qcow2格式. # virt-sparsify --compress --convert qcow2 ubuntu.img ubun ...
- Git 怎样保证fork出来的project和原project(上游项目)同步更新
1. 在 Fork 的代码库中添加上游代码库的 remote 源,该操作只需操作一次即可. 如: 其中# upstream 表示上游代码库名, 可以任意. git remote add upstre ...
- 【转】基于LDA的Topic Model变形
转载自wentingtu 基于LDA的Topic Model变形最近几年来,随着LDA的产生和发展,涌现出了一批搞Topic Model的牛人.我主要关注了下面这位大牛和他的学生:David M. B ...
- static总结
[本文链接] http://www.cnblogs.com/hellogiser/p/static.html [分析] [内存分配方式] 在C++中,内存分成5个区,他们分别是堆.栈.自由存储区.全局 ...
- Delphi经验总结(3)
------------------------------------------------------- ◇删掉程序自己的exe文件 procedure TForm1.FormClose(Sen ...
- Java for LeetCode 139 Word Break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...
- Intellij Idea无法从Controller跳转到视图页面的解决方案
解决方案: 第一步,确认配置了Spring支持,如下图: 一般情况下,配置完上面就可以正常导航了,但是今天要说的不是一般情况,否则也就不说了,如果经过第一步设置后,还是不能正常导航的同学,可以接着看第 ...