贪心算法设计 之最少硬币数目
来源:互联网 发布:淘宝信欣美妆靠谱吗 编辑:程序博客网 时间:2024/05/21 07:15
//题目描述:现在有1元,5元,10元,50元,100元,500元的硬币各c1,c2...c6枚//现在需要去付钱数为A元,问,至少需要多少枚硬币//算法:只需要不断选择面值大的硬币就可以了,因为问题保证有解#include<iostream>#include<string.h>#include<algorithm>using namespace std;int A, v[6] = { 1, 5, 10, 50, 100, 500 }, c[6];int main(){while (cin >> A){memset(c, 0, sizeof(c));//inputfor (int i = 0; i < 6; i++){cin >> c[i];}int ans = 0;//from big to smallfor (int i = 5; i >= 0; i--){int t = min(A / v[i], c[i]);A -= t*v[i];ans += t;}cout << ans << endl;}return 0;}
0 0
- 贪心算法设计 之最少硬币数目
- 经典算法贪心法之最少硬币
- 最少硬币问题--贪心算法
- 贪心算法最少硬币数
- 贪心算法之硬币问题
- 最少硬币问题-贪心选择
- 硬币组合问题之最少硬币个数
- 贪心算法-找硬币
- 贪心算法:硬币问题
- 贪心算法-翻硬币
- 动态规划之最少硬币
- 算法设计之贪心
- 硬币找零(贪心算法)
- 贪心算法(硬币问题)
- 最少硬币
- 动态规划之最少硬币问题
- 动态规划之最少硬币凑钱问题
- 动态规划之最少硬币找零问题
- poj 2424 Flo's Restaurant
- 宏展开中遇到意外的文件结束
- iOS设计模式之三:MVC模式
- 在Mac OS下中下载与安装jdk
- POJ 1141 Brackets Sequence
- 贪心算法设计 之最少硬币数目
- 分治法 求 逆序对数 的个数 时间复杂度为O(n*logn)
- Spring MVC对比Struts2
- mac xcode运行opengl
- LeetCode #Longest Substring Without Repeating Characters#
- 阿里巴巴2016实习生招聘编程题
- NYOJ Yougth的最大化
- sysobjects 表结构
- c语言004---预处理