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 < ...
随机推荐
- Pywinauto使用方法
3 Pywinauto使用 连接为 http://pywinauto.github.io/ 3.1 关联到一个应用,用以下方法: ? start_(path) connect_(handle or p ...
- LIUNX随堂学习-1 用户及查看信息
1.useradd #创建用户 例如:useradd ljj 创建一个名为ljj的用户 2.userdel -r #删除用户 例如:userd ...
- Django 1.8.2 admin 数据库操作按下保存按钮出错
Django报错:Runtimeerror: generator raised StopIteration python版本太新不兼容照成,下载python3.6就行了
- STM32的I2C通讯过程
使用I2C外设通讯时,在通讯的不同阶段它会对“状态寄存器(SR1 及SR2)”的不同数据位写入参数,通过读取这些寄存器标志来了解通讯状态. 1.主发送器 可使用STM32标准库函数来直接检测这些事件的 ...
- asp.net core-15.Individual authentication 模板
在visual studio code执行dotnet new mvc --help 可以查看执行命令 visual studio code先创建一个mvc的项目 dotnet new mvc -au ...
- The Heaviest Non-decreasing Subsequence Problem
最长非递减子序列变形题,把大于等于10000的copy五次放回去就可以了 ac代码: #include <cstdio> #include <cstring> #include ...
- 一次腾讯云centos服务器被入侵的处理
昨天一大早,我还没到公司呢,就收到腾讯云安全中心发来的服务器异常登录告警,登录控制台一看,ip还是美国的,一脸懵逼.由于本人之前也没有过处理服务器入侵的经验,而且这台服务器目前还没有部署商用系统,所以 ...
- 基于【 MySql 】一 || 主从复制
一.centos7安装mysql 1. 先检查系统是否装有mysql rpm -qa | grep mysql 2. 下载mysql的repo源 wget http://repo.mysql.com/ ...
- windows环境安装haproxy及初步配置负载均衡使用示例
安装HaProxy 首先需要下载windows环境下需要文件,这里下载的是一个别人编译好的一个文件,这里省去了编译的过程,使用的版本是haproxy-1.7.8. 下载后直接解压到对应的目录下.示例( ...
- github release 文件下载贼慢,干脆失败的解决方法
链接:Free Download Manager 5提取码:4194 Free Download Manager 下载工具可以解决Github 下载缓慢或失败问题,至少能加快下载速度. 如果嫌百度网盘 ...