CCF NOI1034 钞票兑换

问题链接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
", 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
", count);

    return 0;
}





原文地址:https://www.cnblogs.com/tigerisland/p/7563868.html