[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(贪心)的更多相关文章

  1. A. Optimal Currency Exchange 兑换硬币,剩下的钱最少

    A. Optimal Currency Exchange time limit per test 1.5 seconds memory limit per test 512 megabytes inp ...

  2. POJ1860 Currency Exchange(bellman-ford)

    链接:http://poj.org/problem?id=1860 Currency Exchange Description Several currency exchange points are ...

  3. 图论 --- spfa + 链式向前星 : 判断是否存在正权回路 poj 1860 : Currency Exchange

    Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 19881   Accepted: 711 ...

  4. Currency Exchange(Bellman-ford)

    Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 21349   Accepted: 765 ...

  5. poj1860 bellman—ford队列优化 Currency Exchange

    Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 22123   Accepted: 799 ...

  6. 最短路(Bellman_Ford) POJ 1860 Currency Exchange

    题目传送门 /* 最短路(Bellman_Ford):求负环的思路,但是反过来用,即找正环 详细解释:http://blog.csdn.net/lyy289065406/article/details ...

  7. Currency Exchange 分类: POJ 2015-07-14 16:20 10人阅读 评论(0) 收藏

    Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22180 Accepted: 8015 De ...

  8. POJ 1860 Currency Exchange (最短路)

    Currency Exchange Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 60000/30000K (Java/Other) T ...

  9. poj 1860 Currency Exchange :bellman-ford

    点击打开链接 Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16635   Accept ...

随机推荐

  1. Java面试之持久层(10)

    91,什么是ORM?         对象关系映射(Object-Relational Mapping,简称ORM)是一种为了解决程序的面向对象模型与数据库的关系模型互不匹配问题的技术: 简单的说,O ...

  2. ETL工具之kittle使用案例整理

    主花了一下午时间,收集全网,学习了下kittle,觉得该大v写的不错,特意整理给大家!学会这几个案例kittle基本就没问题了. 1.kettle案例一抽取gz格式文本内容保存到mongodb  ht ...

  3. CodeForces 1100F Ivan and Burgers

    CodeForces题面 Time limit 3000 ms Memory limit 262144 kB Source Codeforces Round #532 (Div. 2) Tags da ...

  4. Tarjan算法初步

    一.前置知识: 强连通分量:有向图强连通分量:在有向图G中,如果两个顶点vi,vj间(vi>vj)有一条从vi到vj的有向路径,同时还有一条从vj到vi的有向路径,则称两个顶点强连通(stron ...

  5. (65)CRC32校验C语言版本

    #include<iostream> # include <stdio.h> # include <string.h> typedef unsigned int u ...

  6. json根据一个值返回对象,filter方法使用

    d = {   "student":[     {       "count":1000,       "stuList":[        ...

  7. 读写锁StampedLock的思想

    该类是一个读写锁的改进,它的思想是读写锁中读不仅不阻塞读,同时也不应该阻塞写. 读不阻塞写的实现思路: 在读的时候如果发生了写,则应当重读而不是在读的时候直接阻塞写! 因为在读线程非常多而写线程比较少 ...

  8. CentOS 6.5系统使用yum方式安装LAMP环境和phpMyAdmin,mysql8.0.1/mysql5.7.22+centos7,windows mysql安装、配置

    介绍如何在CentOs6.2下面使用YUM配置安装LAMP环境,一些兄弟也很喜欢使用编译的安装方法,个人觉得如果不是对服务器做定制,用yum安装稳定简单,何必去download&make&am ...

  9. 系统性能信息模块--psutil

    #安装psutil模块#pip install psutil -i https://pypi.doubanio.com/simple #导入psutil模块import psutilimport da ...

  10. phpmyadmin普通用户使用配置

    正常情况需求是,普通用户可以管理特定的数据库,可能也需要能新建数据库,配置如下: 1.添加用户,phpmyadmin和应用访问,所以主机设置127.0.0.1访问即可 2.如果只管理一个数据,可以选择 ...