题意:给定n个卢布,给出兑换1个欧元和1个美元所需卢布,求出在兑换若干欧元或者美元之后剩下的最少卢布数。美元面值:1, 2, 5, 10, 20, 50, 100,欧元面值:5 , 10, 20, 50, 100, 200
思路:题目说的不是很清楚,实际上可以兑换任意数量的美元或欧元,只要有这个面值即可。显然兑换美元判断能否除得1即可,欧元则判断能否除得5。选择美元或欧元枚举,取最小答案输出即可
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+5;
const int inf = 0x3f3f3f3f;
int n, d, e;
int main()
{
cin >> n >> d >> e;
e *= 5;
if (n % d == 0 || n % e == 0) {
cout << 0 << "\n";
return 0;
}
int r = n%e, ans = r;
while (r <= n) {
int t = r % d;
if (t < ans)
ans = t;
r += e;
}
cout << ans << "\n";
return 0;
}