UVAlive 7503
来源:互联网 发布:reveal.js 幻灯片 编辑:程序博客网 时间:2024/04/29 11:09
题意:你有a(0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50)钱,有一个机器,在这个机器上,你可以花任意的钱,然后它会把零钱以不确定的方式吐出来(由0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50中的任意个,把零钱凑出来),然后问,如果想通过在这个机器上花费任意的钱(这个机器可以使用任意次,呵呵了),来得到b的零钱,问最少花多少钱就能达到目的。
思路:推规律,一般的,只需要一分钱就能得到b的零钱,除了b是0.01,0.1,1.10的时候不一样,当b是这些钱的时候,花一分的话,比如a是0.5的时候,他很有可能会吐出0.2 0.2 0.05 0.02 0.02,这样的话是得不到0.01的,所以只能再花一分钱,才能保证绝对能得到0.01当时场上错了三次,眼瞎没看见能用很多次。。。
当时EC-FINAL上的一道题,场上封榜前出的最后一道题。。。
#include<cstdio>#include<cstring>#include<vector>#include<queue>#include<iostream>#include<algorithm>using namespace std;typedef long long ll;const int maxn = 1024;const int INF = 0x3f3f3f3f;const int mod = 1000000007;int main(){ int n; scanf("%d",&n); int kase = 1; while(n--) { double a,b; scanf("%lf%lf",&a,&b); printf("Case #%d: ",kase++); if(a == b*2) { printf("0.01\n"); continue; } if(b == 0.01||b == 0.1||b == 1||b == 10||b == 100) { printf("0.02\n"); } else { printf("0.01\n"); } } return 0;}
0 0
- UVALive 7503
- UVAlive 7503
- Uvalive 7503
- UVALive 7503--模拟
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- 关于try catch finally中的一些问题
- HDU 2181 哈密顿绕行世界问题
- [Go语言]我的第十个Go语言程序
- C++虚表
- KVO & KVC 的比较 - KVO
- UVAlive 7503
- cloudwatch构建运维监控——默认监控服务
- Python学习笔记:对象,值和类型
- oracle闪回技术
- 自定义IndicatorListView——带Group指示器的ListView
- java九大内置对象
- 使用Java的内省和注解将JavaBean转换成Map
- 关于requestWindowFeature(Window.Feature_no_Title);失效的问题
- SpringMVC的@ResponseBody中文返回问号