[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 ...
随机推荐
- CSS无图片三角形
border:6px solid #f2f2f2; border-color:#999 transparent transparent transparent; border-style:solid ...
- ZOJ 2301 离散化
题目链接: 题意是说,有从 1 开始递增依次编号的很多球,开始他们都是黑色的,现在依次给出 n 个操作(ai,bi,ci),每个操作都是把编号 ai 到 bi 区间内的所有球涂成 ci 表示的颜色(黑 ...
- codevs 1002 搭桥x
题目描述 Description 有一矩形区域的城市中建筑了若干建筑物,如果某两个单元格有一个点相联系,则它们属于同一座建筑物.现在想在这些建筑物之间搭建一些桥梁,其中桥梁只能沿着矩形的方格的边沿搭建 ...
- Python实现用户注册到文件
import getpass #引入getpass模块,主要用来输入密码关闭回显 f=open('d:/user','a+') #定义文件对象并以追加方式打开,不存在就创建 f.seek(0) #文件 ...
- Windows10系统内置Linux
主要是在等电脑安装系统,有点慢,于是写个博客…… 还是那句话,从今年开始NOIP应该就不让用Windows了,所以还是尽早转Linux吧,不然NOIP考场上不会编译太尴尬对吧. 在学校电脑有Linux ...
- 阿里知识储备之二——junit学习以及android单元测试
一,junit框架 http://blog.csdn.net/afeilxc/article/details/6218908 详细见这篇博客 juit目前已经可以和maven项目进行集成和测试,而且貌 ...
- 测试常用命令之awk篇
awk/gawk 1,内置变量 FILENAME:输入文件名称 FNR:当前数据文件中的数据行数 NF:数据文件中的字段总数 NR:已处理的输入数据行数目 FS:输入数据段分隔符 RS:输入数据行分隔 ...
- phpstudy composer 安装
今天突然发现phpstudy 可以安装 composer 一打开php中openssl拓展 坑一 我的phpstudy 是2018最新版本,但是你下载laravel什么之类库会报错,是由于compo ...
- 编译Chrome详细步骤
编译Chrome详细步骤 文章来源:http://blog.csdn.net/allendale/article/details/9262833 参考:http://dev.chromium.or ...
- IO负载高来源定位pt-ioprofile
1.使用top -d 1 查看%wa是否有等待IO完成的cpu时间,简单理解就是指cpu等待磁盘写入完成的时间:IO等待所占用的cpu时间的百分比,高过30%时IO压力高: 2.使用iostat -d ...