Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) A题
A. Optimal Currency Exchange
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 n 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 d rubles, and one euro costs e rubles.
Recall that there exist the following dollar bills: 1, 2, 5, 10, 20, 50, 100, and the following euro bills — 5, 10, 20, 50, 100, 200 (note that, in this problem we do not consider the 500 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 n, e and d, 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 n (1≤n≤108) — the initial sum in rubles Andrew has.
The second line of the input contains one integer d (30≤d≤100) — the price of one dollar in rubles.
The third line of the input contains integer e (30≤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.
Input
Output
Input
Output
题意:有n个卢布,要换成美元和欧元,使手上剩余的卢克最少。一美元价值d卢布,一欧元价值e卢克。
思路:欧元的面值最小为5,则只需找5的倍数,美元最小面值为1。
写法:枚举。
AC代码:
//欧元的面值最小为5,其实的都少5的倍数,美元最小面值为1。
/*
1 dollar---> d rubles
1 euro ----> e rubles dollar 1 2 5 10 20 50 100
euro 5 10 20 50 100 200 */
#include<bits/stdc++.h> using namespace std; #define int long long signed main(){
int n,d,e;
cin>>n>>d>>e;
int ans=n;
int x1=n/e;
if(x1<){
printf("%lld\n",n-(n/d)*d);return ;
}else{
int t1=n/(e*);
for(int i=;i<=t1;i++){
int temp=n;
temp=temp-e*i*-((n-e*i*)/d)*d;
//int sum2=temp-(temp/d)*d;
ans=min(ans,temp);
}
printf("%lld\n",ans); }
return ;
}
Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) A题的更多相关文章
- Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) C题
C. Bad Sequence Problem Description: Petya's friends made him a birthday present — a bracket sequenc ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Educational Codeforces Round 39 (Rated for Div. 2) G
Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...
随机推荐
- Word 查找替换高级玩法系列之 -- 查找文档中的叠字
叠字,顾名思义,就是重复出现,叠加在一起的文字,多多少少.点点滴滴等都属于这类范畴.而当Word文档中出现这类文字的时候我们应该怎么鉴别呢?如何找到这些叠字? 李清照的<声声慢>一词相信大 ...
- 有关Linux服务器的一些配置
1.Redis部署 1.版本 redis-3.0.72.上传解压 3.编译 make && make install 问题:/bin/sh: cc: command not found ...
- Python3 使用pygal 生成世界人口地图
最近在看<python从入门到实践>,其中有一个例子是使用pygal制作世界人口地图,觉得挺有意思的,这里就记录下来了, 其实代码不是很复杂,使用环境环境python3.废话不多说,直接上 ...
- Mysql 集群环境搭建
在上一篇文章中已经详细的写了关于Mysql的安装步骤.这一篇文章在上一篇文章的基础之上接着写集群的安装与部署. 安装地址:https://www.cnblogs.com/ming-blogs/p/10 ...
- WebAPI 笔记
一.基本配置 1. 全局配置 Global.asax public class WebApiApplication : System.Web.HttpApplication { protected v ...
- ASP.NET WEB应用程序(.network4.5)MVC Razor视图引擎2 Areas区域说明
https://www.cnblogs.com/webapi/p/5976642.html Asp.Net MVC Areas区域说明 一般网站分为前台+会员后台+管理员后台,做过webform的 ...
- Django对postgresql数据库进行分组聚合查询
action(methods=['GET'], detail=False, url_path='count') def count(self, request): """ ...
- 1 vue 关键字解释
1 每一个计算属性都包含一个getter和一个setter,计算属性可以依赖其他计算属性,计算属性可以依赖当前vue实例的数据也可以依赖其他vue实例的数据 2 计算属性是基于它的依赖缓存的,方法则是 ...
- SAP UI5的support Assistant
SAP UI5的support Assistant给UI5刚入门的开发人员提供了一种极便利的快速熟悉UI5代码的途径. 召唤方式: ctrl+shift+alt+p四个键同时按,在弹出的对话框里点击按 ...
- ASE19团队项目beta阶段Backend组 scrum5 记录
本次会议于12月11日,19:30在微软北京西二号楼sky garden召开,持续10分钟. 与会人员:Zhikai Chen, Lihao Ran, Xin Kang 请假人员:Hao Wang 每 ...