博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVALive 7503 Change(乱搞)题解
阅读量:4657 次
发布时间:2019-06-09

本文共 1762 字,大约阅读时间需要 5 分钟。

题意:你现在有面额为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
#include
#include
#include
#include
#include
#include
#include
#include
typedef long long ll;using namespace std;const int maxn = 1000 + 10;const int MOD = 1e9 + 7;const int INF = 0x3f3f3f3f;int main(){ int t, ca = 1; 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 == 1){ //3.99 if(a == 2) printf("0.01\n"); else if(a == 5) printf("0.02\n"); else printf("0.02\n"); } else if(b == 2){ //4.99 9.99 if(a == 5) printf("0.01\n"); else printf("0.01\n"); } else if(b == 5){ //9.99 printf("0.01\n"); } else if(b == 10){ //39.99 if(a == 20) printf("0.01\n"); else printf("0.02\n"); } else if(b == 20){ //49.99 99.99 if(a == 50) printf("0.01\n"); else printf("0.01\n"); } else{ //99.99 printf("0.01\n"); } } return 0;}

 

转载于:https://www.cnblogs.com/KirinSB/p/10328002.html

你可能感兴趣的文章
kvm 虚拟化的使用
查看>>
一个删除磁盘文件的恶意软件分析
查看>>
react组件里阻事件冒泡
查看>>
Maven中的dependencyManagement 意义
查看>>
Navicat连接oracle,出现Only compatible with oci version 8.1 and&nb (转)
查看>>
Target runtime com.genuitec.runtime.generic.jee60 is not defined
查看>>
为什么要使用NoSQL
查看>>
第二次Soring冲刺计划第五天(团队)
查看>>
使用反射、特性简化代码
查看>>
emoj表情插入mysql,取出mysql的处理工具类
查看>>
jdk环境搭建
查看>>
学习算法之路(转)
查看>>
java中构造方法及其作用
查看>>
实现Magento多文件上传代码功能开发
查看>>
HttpURLConnection
查看>>
包与模块--内置
查看>>
vs2017新建一个空项目
查看>>
[转]Java中使用Runtime和Process类运行外部程序
查看>>
Java中的集合Queue、LinkedList、PriorityQueue(四)
查看>>
Excel操作之VLOOKUP函数
查看>>