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 ...
随机推荐
- 【CSS属性#1】
" 目录 一.宽和高 二.字体属性 1. 文字字体 font-famlly 2. 字体大小 font-size 3. 字重(粗细) font-weight 4. 文本颜色 color 三.字 ...
- wsgiref模块
学习django框架之前,可以先学习一下wsgiref模块,熟悉前后端交互. 一.先介绍下wsgiref模块 WSGI(Web Server Gateway Interface)是一种规范,它定义了使 ...
- C语言:统计整型变量m中各数字出现的次数,-去掉一个最高分和一个最低分,然后求平均值,(注意最低分和最高分可能有多个数并列)
//统计整型变量m中各数字出现的次数,并存放在数组a中,其中,a[0]存放0出现的次数,a[1]存放1出现的次数. #include <stdio.h> ]) { int i; ; i&l ...
- 解决:jenkins jnlp安装 provided port 40127 is not reachable
解决方法: 开放linux 防火墙40127端口允许下载jnlp centos7 解决如下: [root@hostuser chrome]# firewall-cmd --zone=public -- ...
- Docker容器CPU限制选项测试
目录 Docker容器CPU限制选项测试 参考 实验环境 --cpu-shares选项 测试 结论 --cpus选项 测试 结论 --cpuset-cpus选项 测试 结论 Docker容器CPU限制 ...
- idea垂直分屏
1.找到分屏功能 搜索keymap(注意大小写): 2.Split Vertically 垂直分屏/Split Horizontally 水平分屏 3.添加快捷方式
- 微服务、分库分表、分布式事务管理、APM链路跟踪性能分析演示项目
好多年没发博,最近有时间整理些东西,分享给大家. 所有内容都在github项目liuzhibin-cn/my-demo中,基于SpringBoot,演示Dubbo微服务 + Mycat, Shardi ...
- 顾家办公两不误,容智ibot帮你实现高效居家办公
春节假期结束,大部分企业已陆续开始复工.经调查显示,受新型冠状病毒疫情影响,不少企业开放了员工“在家办公“模式,就此,员工被动“SOHO”,在家办公火了. 2020 在家办公靠谱吗?会不会成为未来的趋 ...
- python3.8的PySimpleGUI学习的温度转换(℃转℉)
一.代码1: #导出模块 import PySimpleGUI as sg #总体布局,sg.InputText(),默认size=(45,1). layout = [ [sg.Text('Celci ...
- vs code插件大全
一.HTML Snippets 超级使用且初级的H5代码片段以及提示 二.HTML CSS Support 让HTML标签上写class智能提示当前项目所支持的样式 三.Debugger for C ...