UVALive 7503 Change(乱搞)题解

时间:2023-03-09 17:03:53
UVALive 7503 Change(乱搞)题解

题意:你现在有面额为A的纸币,现在需要面额为B的钱(可以是一张也可以是好多张拼成一张),有一台自动售货机,里面有任意价格的商品,售货机兑换出的零钱是随机的(比如找你0.03可能给你0.01+0.01+0.01也可能是0.01+0.02),那么问至少要花多少钱你肯定能兑换到所需要的面额。A, B ∈ {0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, 100} and A > B

思路:题意读错了...这里的意思不是你只能买一个东西,而是你买了之后可以用找零的钱继续买,那么如果0.01可以解决那么就是0.01,其他的只要用零钱继续0.01就可以了。

代码:

#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<cstdio>
#include<cstring>
#include<sstream>
#include<algorithm>
typedef long long ll;
using namespace std;
const int maxn = + ;
const int MOD = 1e9 + ;
const int INF = 0x3f3f3f3f;
int main(){
int t, ca = ;
scanf("%d", &t);
while(t--){
double a, b;
scanf("%lf%lf", &a, &b);
printf("Case #%d: ", ca++);
if(b == 0.01){ //0.03
if(a == 0.02){
printf("0.01\n");
}
else if(a == 0.05){
printf("0.02\n");
}
else{
printf("0.02\n");
}
}
else if(b == 0.02){ //0.04 0.09
if(a == 0.05){
printf("0.01\n");
}
else{
printf("0.01\n");
}
}
else if(b == 0.05){ //0.09
printf("0.01\n");
}
else if(b == 0.1){ //0.39
if(a == 0.2) printf("0.01\n");
else if(a == 0.5) printf("0.02\n");
else printf("0.02\n");
}
else if(b == 0.2){ //0.49 0.99
if(a == 0.5) printf("0.01\n");
else printf("0.01\n");
}
else if(b == 0.5){ //0.99
printf("0.01\n");
}
else if(b == ){ //3.99
if(a == ) printf("0.01\n");
else if(a == ) printf("0.02\n");
else printf("0.02\n");
}
else if(b == ){ //4.99 9.99
if(a == ) printf("0.01\n");
else printf("0.01\n");
}
else if(b == ){ //9.99
printf("0.01\n");
}
else if(b == ){ //39.99
if(a == ) printf("0.01\n");
else printf("0.02\n");
}
else if(b == ){ //49.99 99.99
if(a == ) printf("0.01\n");
else printf("0.01\n");
}
else{ //99.99
printf("0.01\n");
}
}
return ;
}