hdu 2566 统计硬币

来源:互联网 发布:js格式化代码插件 编辑:程序博客网 时间:2024/05/19 13:43

方法:设1分的为x个,2分的为y个,则x+2y+5(n-x-y)==m, 得5n-m==4x+3y;

注意:x+y<=n;

java代码:

import java.util.Scanner;public class Main {    static int t, n, m;    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        t = sc.nextInt();        int count = 0;        int sum = 0;        while (t-- > 0) {            n = sc.nextInt();            m = sc.nextInt();            count = 0;            sum = 5 * n - m;            for (int i = 0; i <= n; i++) {                for (int j = 0; j <= n; j++) {                    if (sum == 4 * i + 3 * j && i + j <= n) {                        count++;                    }                }            }            System.out.println(count);        }    }}




统计硬币

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5281    Accepted Submission(s): 3646


Problem Description
假设一堆由1分、2分、5分组成的n个硬币总面值为m分,求一共有多少种可能的组合方式(某种面值的硬币可以数量可以为0)。
 

Input
输入数据第一行有一个正整数T,表示有T组测试数据;
接下来的T行,每行有两个数n,m,n和m的含义同上。
 

Output
对于每组测试数据,请输出可能的组合方式数;
每组输出占一行。
 

Sample Input
23 54 8
 

Sample Output
12
 

Author
lemon
 

Source
绍兴托普信息技术职业技术学院——第二届电脑文化节程序设计竞赛
 

Recommend
yifenfei   |   We have carefully selected several similar problems for you:  1085 2152 1171 1398 2082 


0 0