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; }

좋은 웹페이지 즐겨찾기