A. Optimal Currency Exchange

time limit per test

1.5 seconds

memory limit per test

512 megabytes

input

standard input

output

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.

Input

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

Output one integer — the minimum number of rubles Andrew can have after buying dollar and euro bills optimally.

Examples
input

Copy
100
60
70
output

Copy
40
input

Copy
410
55
70
output

Copy
5
input

Copy
600
60
70
output

Copy
0
Note

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 兑换硬币,剩下的钱最少的更多相关文章

  1. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

  2. Currency Exchange POJ - 1860 (spfa)

    题目链接:Currency Exchange 题意: 钱的种类为N,M条命令,拥有种类为S这类钱的数目为V,命令为将a换成b,剩下的四个数为a对b的汇率和a换成b的税,b对a的汇率和b换成a的税,公式 ...

  3. Currency Exchange(最短路)

    poj—— 1860 Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 29851   Ac ...

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

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

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

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

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

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

  7. POJ 1860 Currency Exchange (bellman-ford判负环)

    Currency Exchange 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/E Description Several c ...

  8. Currency Exchange POJ - 1860 (spfa判断正环)

    Several currency exchange points are working in our city. Let us suppose that each point specializes ...

  9. POJ 1860 Currency Exchange(如何Bellman-Ford算法判断图中是否存在正环)

    题目链接: https://cn.vjudge.net/problem/POJ-1860 Several currency exchange points are working in our cit ...

随机推荐

  1. python加密算法及其相关模块的学习(hashlib,RSA,random,string,math)

    加密算法介绍 一,HASH Hash,一般翻译做“散列”,也有直接音译为”哈希”的,就是把任意长度的输入(又叫做预映射,pre-image),通过散列算法,变换成固定长度的输出,该输出就是散列值.这种 ...

  2. C语言:将3*4矩阵中找出行最大,列最小的那个元素。-将低于平均值的人数作为函数返回值,将低于平均分的分数放入below数组中。

    //将3*4矩阵中找出行最大,列最小的那个元素. #include <stdio.h> #define M 3 #define N 4 void fun(int (*a)[N]) { ,j ...

  3. ASP.NET Core搭建多层网站架构【11-WebApi统一处理返回值、异常】

    2020/02/01, ASP.NET Core 3.1, VS2019 摘要:基于ASP.NET Core 3.1 WebApi搭建后端多层网站架构[11-WebApi统一处理返回值.异常] 使用I ...

  4. Tensorflow机器学习入门——常量、变量、placeholder和基本运算

    一.这里列出了tensorflow的一些基本函数,比较全面:https://blog.csdn.net/M_Z_G_Y/article/details/80523834 二.这里是tensortflo ...

  5. 创业学习---《预判项目的长期壁垒》--B-3.预判模块---HHR计划---以太一堂

    一,<开始学习> 1,投资人经常会问CEO:你的项目的长期壁垒是什么?你是怎么思考的? 2,三个预热思考题: (1)突然有一天,大公司要抄你,你会怎么办?  答:用增长技术来和他竞争. ( ...

  6. Euler Sums系列(三)

    \[\Large\sum_{n=1}^{\infty}\frac{\left(H_{n}^{(2)}\right)^{2}}{n^{2}}=\frac{19}{24}\zeta(6)+\zeta^{2 ...

  7. Docker 安装 Filebeat

    使用同版本镜像 7.4.1 1.下载Filebeat镜像 docker pull store/elastic/filebeat: docker images 2.下载默认官方配置文件wget http ...

  8. Nexus-vPC与FHRP

    去往vPC的流量,如何可能将会被本地的vPC成员端口所转发.FHRP的行为是被修改的,所有的FHRP路由器都会主动转发从vPC收到的流量.修改结果:如果可能,流量避免使用Peer link,这样创建一 ...

  9. ES-倒排索引

    一.什么事倒排索引 二.倒排索引为什么查询速度快 (1)ES全文检索的底层是使用倒排索引实现的 (2)倒排索引会将文档的内容进行关键词分词,可以使用关键词直接定位到文档的内容

  10. 【SSM sql.xml】日志查询mapper.xml

    LogInfoMapper.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapp ...