题意: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;
}