UVALive 7503--模拟
来源:互联网 发布:dfd软件 编辑:程序博客网 时间:2024/05/16 09:57
题意:
你有A元,你需要通过买东西凑出B元,A, B ∈ {0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, 100} 且 A > B,注意:可以先买一个
东西,之后拿找零的钱继续买东西。
输入:
2
0.05 0.02
2 1
输出:
0.01
0.01
分析:
只要读懂题意,并不难模拟出来,由于可以拿找零的钱继续买东西,所以,只需要找不能用小钱凑的临界点就可以,即0.01,0.1,1,10,
这些对应他们的上两级,都是需要先买1分的东西,再拿找零的钱再买一分的东西,也就是总共花两分,而其他的情况则是只是花一
分。
代码:
#include <cstdio>#include <cstring>#include <cmath>using namespace std;//double k[] = {0.01,0.02,0.05,0.1,0.2,0.5,1,2,5,10,20,50,100};double fun(double a,double b){ if((b==0.01)&&(a==0.05)) return 0.02; else if((b==0.01)&&((a==0.1)||(a==0.2)||(a==0.5)||(a==1)||(a==2)||(a==5)||(a==10)||(a==20)||(a==50)||(a==100))) return 0.02; else if((b==0.1)&&(a==0.5)) return 0.02; else if((b==0.1)&&((a==1)||(a==2)||(a==5)||(a==10)||(a==20)||(a==50)||(a==100))) return 0.02; else if((b==1)&&(a==5)) return 0.02; else if((b==1)&&((a==10)||(a==20)||(a==50)||(a==100))) return 0.02; else if((b==10)&&(a==50)) return 0.02; else if((b==10)&&((a==100))) return 0.02; else return 0.01;}int main(){ int T; double a,b;// init(); scanf("%d",&T); int kase = 0; while(T--) { scanf("%lf%lf",&a,&b); printf("Case #%d: %.2f\n", ++kase, fun(a, b)); } return 0;}
0 0
- UVALive 7503--模拟
- UVALive 3497 brainfuck [模拟]
- UVALive 4723 水模拟
- UVALive 6833 (模拟 水~)
- UValive 7269 (模拟)
- UVALive 6833【模拟】
- UVALive 7327【模拟】
- UVALive 7608Robot(模拟)
- UVALive 7752 模拟
- 【模拟】 UVALive 4168 Lampyridae Teleportae
- UvaLive--6664--Clock Hands【模拟】
- UVALive 4887 Soccer 状压+模拟
- UVALive 3971 Assemble(模拟 + 二分)
- UVALive 6833Miscalculation (模拟)
- UVALive - 6269 Digital Clock 模拟
- UVALive 5873 - Tree Inspections 【模拟】
- uvalive 4254(二分+模拟)
- UVALive 7139 Rotation(模拟)
- POJ 2184 Cow Exhibition
- [Go语言]我的第八个Go语言程序
- hdoj1325Is It A Tree?(并查集)
- La 4128 Steam Roller 状态图上的Dijkstra
- 实现支付宝支付从底部弹窗效果
- UVALive 7503--模拟
- CSUOJ 1592 石子归并(区间DP)
- nginx+tomcat动态分离
- android一些配置
- python的dataframe和matrix的互换
- C语言程序设计谭浩强版 九
- hdu 5631 (Rikka with Graph)
- [LeetCode] 72. Edit Distance
- HDU:1325 Is It A Tree?(并查集+有向图树的判断)