zoukankan      html  css  js  c++  java
  • Optimal Currency Exchange

    题目链接:http://codeforces.com/contest/1214/problem/A

    题意: 给出n卢布,并对应给出一美元可兑换的卢布金额和一欧元可兑换的卢布金额,同时给出了不同的美元面额和欧元面额,问兑换后(可以任意兑换,或同时兑换美元和欧元), 问最少剩下的卢布值为多少。
    思路: 给出的美元面额中,除1以外,其余均为1的倍数;给出的欧元面额中,除5外,其余均为5的倍数,所以不管如何兑换,我们只考虑最小面额,先对一欧元能兑换的金额不断进行累加枚举,再不断一美元能兑换的金额取模更新最小值。详情看代码。

    #include <bits/stdc++.h>
    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;
    } 
    

     
     

  • 相关阅读:
    自定义Filter服务
    filter 以及 orderBy的使用
    ng-repeat-start ng-repeat-end 的使用
    ng-repeat 与ng-switch的简单应用
    ng-bind-html 的使用
    Oracle instr用法
    Oracle left查询案例
    Oracle case用法
    mysql 导出导入sql
    Gson解析复杂JSON对象
  • 原文地址:https://www.cnblogs.com/shmilky/p/14089023.html
Copyright © 2011-2022 走看看