2015ACM-ICPC亚洲区域赛EC-Final D:Change

题目PDF下载

题意:A, B ∈ {0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, 100} ,A > B。假设有A元,用自动售货机花最少的钱使自己的钱能组成B元。

可以换很多次,所以在纸上算算就能找到规律:B为0.01、0.1、1、10时并且A不是0.02、0.2、2、20时,ans=0.02(换两次0.01),否则ans=0.01

#include<cstring>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
    //freopen("a.txt", "r", stdin);
    int t;
    scanf("%d", &t);
    for(int cas = 1; cas <= t; cas++){
        double a, b, ans = 0.01;
        scanf("%lf%lf", &a, &b);
        double aa = a, bb = b;
        while(b < 1){
            b *= 10;
        }
        while(b >= 10){
            b /= 10;
        }
        //cout << cnt1 << endl << cnt2 << endl;
        if(b == 1 && bb*2 != a) ans = 0.02;
        printf("Case #%d: %.2fn", cas, ans);

    }
    return 0;
}
Zhao Li /
Published under (CC) BY-NC-SA in categories 算法  tagged with 2015ecfinal