[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. VUE DIV模拟input框的基本处理

    关键代码 <div class="dialog-main" :contenteditable= "editable" v-text="notic ...

  2. 【leetcode】Path Sum IV

    If the depth of a tree is smaller than 5, then this tree can be represented by a list of three-digit ...

  3. GO语言学习笔记6-Sort的使用

    GoLang标准库的sort包提供了排序切片和用户自定义数据集以及相关功能的函数. Sort操作的对象通常是一个slice,需要满足三个基本的接口,并且能够使用整数来索引. 1.sort实现原理 So ...

  4. postman+newman+jenkins 接口自动化

    一:Jenkins安装: jenkins是一款跨平台的持续集成和持续交付.基于Java开发的开源软件,提供任务构建.持续集成监控的功能,可以使开发测试人员更方便的构建软件项目, 我安装是安装程序模式, ...

  5. 更改pip源地址为阿里云

    1.在用户名目录创建pip目录,在pip目录下创建pip.ini. 2.pip.ini中输入: [global] index-url = http://mirrors.aliyun.com/pypi/ ...

  6. 简单记录一下vue生命周期及 父组件和子组件生命周期钩子执行顺序

    首先,vue生命周期可以用下图来简单理解 当然这也是官方文档的图片,详细的vue周期详解请参考这里 然而当同时存在父子组件的时候生命周期钩子是如何执行的呢? 请看下文: 加载渲染过程父beforeCr ...

  7. 同一个tomcat部署多个项目

    在开发项目中,有时候我们需要在同一个tomcat中部署多个项目,小编之前也是遇到了这样的情况,碰过不少的壁,故整理总结如下,以供大家参考.(以Linux为例,其他系统同样适用) 一.首先将需要部署的项 ...

  8. ENGINE =MyISAM DEFAULT CHARACTER SET latin1 COLLATE latin1_general_cs AUTO_INCREMENT=0; 什么意思

    ENGINE =MyISAM //表类型为myisam插写比较快 DEFAULT CHARACTER  SET  latin1//默认字符为latin1 COLLATE  latin1_general ...

  9. 利用python将两张表链接

    from pyspark.sql import SparkSessionfrom pyspark.sql.types import *import os def getUser(spark,path) ...

  10. 记一次全局分区索引update调优

    原始SQL: CREATE OR REPLACE PROCEDURE sp_upd_suppressed_emails(  A_LIMIT_BULK IN PLS_INTEGER DEFAULT 20 ...