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 e rubles.
Recall that there exist the following dollar bills: 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 d, finds the minimum number of rubles Andrew can get after buying dollar and euro bills.
The first line of the input contains one integer 1≤n≤108) — the initial sum in rubles Andrew has.
The second line of the input contains one integer 30≤d≤100) — the price of one dollar in rubles.
The third line of the input contains integer 30≤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 1 euro bill.
In the second example, optimal exchange is to buy 1 dollar.
In the third example, optimal exchange is to buy 10 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=99999999; cin>>n>>d>>e; for(int i=0;i<=n;i++) ans=min(ans,i%d+(n-i)%e); cout<<ans<<endl; return 0; }