cf1214A A. Optimal Currency Exchange
2781 단어 codeforces
A. Optimal Currency Exchange
time limit per test1.5 seconds
memory limit per test512 megabytes
inputstandard input
outputstandard 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 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.
Examples input 100 60 70 output 40 input 410 55 70 output 5 input 600 60 70 output 0 Note In the first example, we can buy just 1 dollar because there is no 1 euro bill.
In the second example, optimal exchange is to buy 5 euro and 1 dollar.
In the third example, optimal exchange is to buy 10 dollars in one bill. 제목: n루블을 제시하고 1달러의 환전 가능한 루블 금액과 1유로의 환전 가능한 루블 금액을 제시하며 서로 다른 달러 액면과 유로 액면가를 제시한다. 환전 후 (임의로 환전할 수 있거나 달러와 유로를 동시에 환전할 수 있다) 최소한 남은 루블의 가치가 얼마냐고 묻는다.사고방식: 제시된 달러 액면가 중 1을 제외한 나머지는 모두 1의 배수이다.제시된 유로화 액면가 중 5를 제외하고 나머지는 모두 5의 배수이기 때문에 어떻게 환전하든지 간에 우리는 최소 액면가만 고려하여 먼저 1유로화로 환전할 수 있는 금액을 계속 누적하여 매거한 다음에 1달러로 환전할 수 있는 금액을 끊임없이 추출하여 최소치를 갱신한다.자세한 내용은 코드를 보십시오.
#include
using namespace std;
typedef long long ll;
int main() {
int n, d, e;
int a[7] = {1, 2, 5, 10, 20, 50, 100};
int b[6] = {5, 10, 20, 50, 100, 200};
scanf("%d%d%d", &n, &d, &e);
for (int i = 0; i < 7; i++) {
a[i] *= d;
}
for (int i = 0; i < 6; i++) {
b[i] *= e;
}
int ans = 1e9 + 7;
for (int i = 0; i <= n; i += b[0]) { //
ans = min(ans, (n - i) % a[0]); //
}
printf("%d
", ans);
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Codeforces Round #715 Div. 2C The Sports Festival: 구간 DP전형구간 DP의 초전형. 이하, 0-indexed. 입력을 정렬하여 어디서나 시작하고 최적으로 좌우로 계속 유지하면 좋다는 것을 알 수 있습니다. {2000})$의 주문이 된다. 우선, 입력을 소트하여 n개의 요소를 $...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.