[Codeforces 1214A]Optimal Currency Exchange(贪心)
[Codeforces 1214A]Optimal Currency Exchange(贪心)
题面
题面较长,略
分析
这个A题稍微有点思维难度,比赛的时候被孙了一下
贪心的思路是,我们换面值越小的货币越优。如有1,2,5,10,20,50,那么我们尽量用面值为1的。如果我们把原始货币换成面值为x的货币,设汇率为d,那么需要的原始货币为dx的倍数。显然dx越小,剩下的钱,即n取模dx会尽量小。
然后就可以枚举换某一种货币的数量,时间复杂度\(O(\frac{n}{d})\)
代码
#include<iostream>
#include<cstdio>
#define INF 0x3f3f3f3f
using namespace std;
int n,d,e;
int main(){
scanf("%d %d %d",&n,&d,&e);
e*=5;
int ans=INF;
for(int i=0;i*d<=n;i++){
ans=min(ans,n-i*d-(n-i*d)/e*e);
}
printf("%d\n",ans);
}
[Codeforces 1214A]Optimal Currency Exchange(贪心)的更多相关文章
- A. Optimal Currency Exchange 兑换硬币,剩下的钱最少
A. Optimal Currency Exchange time limit per test 1.5 seconds memory limit per test 512 megabytes inp ...
- POJ1860 Currency Exchange(bellman-ford)
链接:http://poj.org/problem?id=1860 Currency Exchange Description Several currency exchange points are ...
- 图论 --- spfa + 链式向前星 : 判断是否存在正权回路 poj 1860 : Currency Exchange
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 19881 Accepted: 711 ...
- Currency Exchange(Bellman-ford)
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21349 Accepted: 765 ...
- poj1860 bellman—ford队列优化 Currency Exchange
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22123 Accepted: 799 ...
- 最短路(Bellman_Ford) POJ 1860 Currency Exchange
题目传送门 /* 最短路(Bellman_Ford):求负环的思路,但是反过来用,即找正环 详细解释:http://blog.csdn.net/lyy289065406/article/details ...
- Currency Exchange 分类: POJ 2015-07-14 16:20 10人阅读 评论(0) 收藏
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22180 Accepted: 8015 De ...
- POJ 1860 Currency Exchange (最短路)
Currency Exchange Time Limit : 2000/1000ms (Java/Other) Memory Limit : 60000/30000K (Java/Other) T ...
- poj 1860 Currency Exchange :bellman-ford
点击打开链接 Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16635 Accept ...
随机推荐
- BZOJ1460: Pku2114 Boatherds
题目链接:点这里 题目描述:给你一棵n个点的带权有根树,有p个询问,每次询问树中是否存在一条长度为Len的路径,如果是,输出Yes否输出No. 数据范围:\(n\le1e5\,,p\le100\,,长 ...
- ZooKeeper设置开机启动
1 在init.d目录下新建脚本文件 进入到/etc/rc.d/init.d目录下,命令是: cd /etc/rc.d/init.d 新建一个名为zookeeper的文件,命令是: touch ...
- es之分页
导入测试数据: POST /_bulk{ "create": { "_index": "us", "_type": &q ...
- vue-router(转)——基本使用 + 路由守卫无限循环问题
路由守卫无限循环问题 https://www.jianshu.com/p/1187f8f74a72 学习目的 学习Vue的必备技能,必须 熟练使用 Vue-router,能够在实际项目中运用. Vue ...
- 二分类算法的评价指标:准确率、精准率、召回率、混淆矩阵、AUC
评价指标是针对同样的数据,输入不同的算法,或者输入相同的算法但参数不同而给出这个算法或者参数好坏的定量指标. 以下为了方便讲解,都以二分类问题为前提进行介绍,其实多分类问题下这些概念都可以得到推广. ...
- 初始化Thread
此处初始化的步骤和上文中介绍的一样,也是调用runClinit方法.首先设置初始化线程为CurrentThread,然后由于其父类Object此时的状态为CLASS_READY,因此就不需要初始化父类 ...
- vue 自己写的一个日历
样式: //quanbu全部代码 <template> <div class="priceListContent clearfix"> <!-- 顶部 ...
- Spring MVC 同一个方法同时返回view或json
https://blog.csdn.net/zzg1229059735/article/details/50854778 @RequestMapping(value = "/htmlorjs ...
- centos7 编译问题:aclocal-1.14: command not found
centos7 编译问题:aclocal-1.14: command not found https://blog.csdn.net/vr7jj/article/details/80438663
- Unity—Compoent类
官方API->Componment 新引入成员 作用 字段 gameobject 该组件所在的游戏对象 tag 游戏对象的标签 Transform 添加在游戏对象上的transform组件 ...