CCF NOI1034 钞票兑换

本文介绍了如何将整百元钞票兑换成10元、20元、50元小钞的不同方案,并提供了两种C语言实现方法。一种是快速简便的方法,另一种则是详细列举所有可能的组合。

问题链接CCF NOI1034 钞票兑换




时间限制: 1000 ms  空间限制: 262144 KB

题目描述 

  将任意给定的整百元钞票,兑换成10元、20元、50元小钞票形式。输出兑换方案总数。

输入

  输入需要兑换的钞票总数n。

输出

  输出方案总数。

样例输入

100
样例输出

10

数据范围限制

  100<=n<=1000000

提示

  方案序号10元张数20元张数50元张数100220503121424053116430750186209810101000




问题分析

  只有三种币种,最大面额的定了,其方案数就可以直接算了

程序说明

  程序采用试探法的逻辑计算结果。

要点详解

  • 使用宏定义可以使得代码可阅读性增强。



参考链接:(略)。

100分通过的C语言程序:

#include <stdio.h>

#define BILL50 50
#define BILL20 20
#define BILL10 10

int main(void)
{
    int n, count, i, end;

    scanf("%d", &n);

    count = 0;
    end = n / BILL50;
    for(i=0; i<=end; i++)
        count += (n - i * BILL50) / BILL20 + 1;

    printf("%d\n", count);

    return 0;
}


100分通过的C语言程序(考虑所有组合,速度慢逻辑繁杂):

#include <stdio.h>

#define BILL50 50
#define BILL20 20
#define BILL10 10

int main(void)
{
    int n, count, i, j, end1, end2;

    scanf("%d", &n);

    count = 0;
    end1 = n / BILL50;
    for(i=0; i<=end1; i++) {
        if(i * BILL50 == n) {
            count++;
            continue;
        }
        end2 = (n - i * BILL50) / BILL20;
        for(j=0; j<=end2; j++) {
            if(i * BILL50 + j * BILL20 == n) {
                count++;
                continue;
            }
            if((n - i * BILL50 - j * BILL20) % BILL10 == 0)
                count++;
        }
    }

    printf("%d\n", count);

    return 0;
}





转载于:https://www.cnblogs.com/tigerisland/p/7563868.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值