列表

详情


NC14746. 栗酱的麻烦

描述

        栗酱这次遇到了一个大麻烦,她手里只有一张大钞,面值为A元,但是现在临时需要花费B块钱了。

        她的花费非常紧急,所以她来到一个小卖部来兑,可是小卖部的老板态度极差,拒绝了栗酱的直接兑换请求。

        栗酱没有办法,周边也没有别的店,栗酱只好在店里强行花费一些钱来获取这个零散的B块钱了。

        但是这个店家十分奇怪,在知道栗酱需要B块钱后,会尽可能地不找给栗酱相应的钱,以获取利益。栗酱赶时间,花多少钱反而不那么重要了,请帮栗酱算一下,只买一次东西,一定能得到B块零钱的最少花费是多少。(货币的面值仅存在这些取值{0.01,0.02,0.05,0.10,0.50,1.00,2.00,5.00,10.00,20.00,50.00,100.00})

输入描述

多组数据,数据第一行T表示数据组数。
每组数据一行,A,B分别代表栗酱当前的大钞和需要的零钱。

输出描述

每组数据一行,输出最少花费。

示例1

输入:

2
0.05 0.01
0.10 0.05

输出:

0.02
0.01

说明:

第一个样例:
如果付0.01块,老板会找你两个0.02。
花0.02老板就没办法了,只能找你一个0.02,一个0.01,或三个0.01

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 3ms, 内存消耗: 360K, 提交时间: 2020-05-25 15:50:40

#include<iostream>
using namespace std;
int main(){
    int t;
    double a, b;
    cin>>t;
    while (t--) {
        cin>>a>>b;
        if (b == 0.01) {
            if (a == 0.02) cout<<0.01<<endl;
            else cout<<a-0.03<<endl;
        }
        else if (b == 1.00) {
            if (a == 2.00) cout<<0.01<<endl;
            else cout<<a-3.99<<endl;
        }
        else if (b == 10.00) {
            if (a == 20.00) cout<<0.01<<endl;
            else cout<<a-39.99<<endl;
        }
        else {
            cout<<0.01<<endl;
        }
 
    }
}

C(clang11) 解法, 执行用时: 1ms, 内存消耗: 356K, 提交时间: 2020-12-25 01:53:15

#include<stdio.h>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        double a,b;
        scanf("%lf%lf",&a,&b);
        if(b==0.01&&a!=0.02)
            printf("%.2f\n",a-0.03);
        else if(b==1&&a!=2)
            printf("%.2f\n",a-3.99);
        else if(b==10&&a!=20)
            printf("%.2f\n",a-39.99);
        else
            printf("0.01\n");
    }
    return 0;
}

C++11(clang++ 3.9) 解法, 执行用时: 3ms, 内存消耗: 376K, 提交时间: 2020-08-15 20:23:30

#include<bits/stdc++.h>
using namespace std;
double A,B,ans;
int main()
{
	int T;
	scanf("%d",&T);
	for(int cas=1;cas<=T;cas++)
	{
		scanf("%lf%lf",&A,&B);
		double ans;
		ans=0.01;
		if(B==0.01&&A>0.02) ans=A-0.03;
		if(B==1&&A>2) ans=A-3.99;
		if(B==10&&A>20) ans=A-39.99;
		cout<<ans<<endl;
	}
	return 0;
}

上一题