A. Optimal Currency Exchange 兑换硬币,剩下的钱最少
A. Optimal Currency Exchange
1.5 seconds
512 megabytes
standard input
standard output
Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has nn rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is dd rubles, and one euro costs ee rubles.
Recall that there exist the following dollar bills: 11, 22, 55, 1010, 2020, 5050, 100100, and the following euro bills — 55, 1010, 2020, 5050, 100100, 200200 (note that, in this problem we do not consider the 500500 euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.
Help him — write a program that given integers nn, ee and dd, finds the minimum number of rubles Andrew can get after buying dollar and euro bills.
The first line of the input contains one integer nn (1≤n≤1081≤n≤108) — the initial sum in rubles Andrew has.
The second line of the input contains one integer dd (30≤d≤10030≤d≤100) — the price of one dollar in rubles.
The third line of the input contains integer ee (30≤e≤10030≤e≤100) — the price of one euro in rubles.
Output one integer — the minimum number of rubles Andrew can have after buying dollar and euro bills optimally.
100
60
70
40
410
55
70
5
600
60
70
0
In the first example, we can buy just 11 dollar because there is no 11 euro bill.
In the second example, optimal exchange is to buy 55 euro and 11 dollar.
In the third example, optimal exchange is to buy 1010 dollars in one bill.
题意:用卢比换美元和欧元,要使剩下的卢比数量最少
题解:给定美元和欧元的汇率分别是 d 和 e ,d是1的倍数,e是5的倍数,枚举x( x<=n ),输出min(ans,x%d+(n-x)%e)即可
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
int n,d,e,ans=;
cin>>n>>d>>e;
for(int i=;i<=n;i++)
ans=min(ans,i%d+(n-i)%e);
cout<<ans<<endl;
return ;
}
A. Optimal Currency Exchange 兑换硬币,剩下的钱最少的更多相关文章
- [Codeforces 1214A]Optimal Currency Exchange(贪心)
[Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...
- Currency Exchange POJ - 1860 (spfa)
题目链接:Currency Exchange 题意: 钱的种类为N,M条命令,拥有种类为S这类钱的数目为V,命令为将a换成b,剩下的四个数为a对b的汇率和a换成b的税,b对a的汇率和b换成a的税,公式 ...
- Currency Exchange(最短路)
poj—— 1860 Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 29851 Ac ...
- 图论 --- spfa + 链式向前星 : 判断是否存在正权回路 poj 1860 : Currency Exchange
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 19881 Accepted: 711 ...
- poj1860 bellman—ford队列优化 Currency Exchange
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22123 Accepted: 799 ...
- 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 (bellman-ford判负环)
Currency Exchange 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/E Description Several c ...
- Currency Exchange POJ - 1860 (spfa判断正环)
Several currency exchange points are working in our city. Let us suppose that each point specializes ...
- POJ 1860 Currency Exchange(如何Bellman-Ford算法判断图中是否存在正环)
题目链接: https://cn.vjudge.net/problem/POJ-1860 Several currency exchange points are working in our cit ...
随机推荐
- 广度优先搜索(BFS)与深度优先搜索(DFS)的对比及优缺点
深搜,顾名思义,是深入其中.直取结果的一种搜索方法. 如果深搜是一个人,那么他的性格一定倔得像头牛!他从一点出发去旅游,只朝着一个方向走,除非路断了,他绝不改变方向!除非四个方向全都不通或遇到终点,他 ...
- Windows10下修改pip源
pip修改源 写在前面 当我们在使用pip的时候,有些时候会觉得pip安装第三方库的时候速度慢得让人抓狂,那是因为pip是从国外的网站下载东西所以呢下载速度很慢,为了方便我们下载,我们可以通过来修改p ...
- SSIS部署后执行失败,无法将保护的XML节点解密
将包属性中的 protectionLevel 设置成DontSaveSensitive 即可.
- Linux - Shebang(#!)
1. Shebang这个符号通常在Unix系统的脚本中第一行开头中写到,它指明了执行这个脚本文件的解释程序.
- JAVA面向对象解决实际问题实例(一)
某次战役中,为便于信息交互,我军侦察部门将此次战役的关键高地坐标设定为(x=0,y=0)并规定,每向东增加100米,x加1,每向北增加100米,y加1.同时,我军情报部门也破译了敌军向坦克发送的指挥信 ...
- Python学习第二十六课——PyMySql(python 链接数据库)
Python 链接数据库: 需要先安装pymysql 包 可以设置中安装,也可以pip install pymysql 安装 加载驱动: import pymysql # 需要先安装pymysql 包 ...
- 自定义 Laravel 5.7 - 6.X 中验证邮箱的标题文本
原理解析: 验证邮箱在Laravel默认实现中是一个Notification,不是Mailable,而为了自定义验证邮箱的默认配置,我们先来查看一下 /vendor/laravel/framework ...
- Update(Stage5):Kudu_javaApi使用_Spark整合
Table of Contents: 2.3. 安装 Zookeeper 2.4. 安装 Hadoop 2.4. 安装 MySQL 2.5. 安装 Hive 2.6. 安装 Kudu 2.7. 安装 ...
- iOS 根据域名查询 IP 地址
在 iOS 开发中,如果需要知道网站的 IP 地址: #include <netdb.h> #include <arpa/inet.h> NSString *webSiteSt ...
- 洛谷P1301 魔鬼之城 题解
想找原题请点击这里:传送门 题目描述 在一个被分割为N*M个正方形房间的矩形魔鬼之城中,一个探险者必须遵循下列规则才能跳跃行动.他必须从(, )进入,从(N, M)走出:在每一房间的墙壁上都写了一个魔 ...