3510 - 硬币兑换
用1元5角钱人民币兑换5分、2分和1分的硬币(每一种都要有)共100枚,
问共有几种兑换方案?每种方案各换多少枚?
题目输入
无输入
题目输出
输出每种方案各多少枚。每一种方案之后换行,三个整数之间以空格隔开
最后一行输出总方案数。
输入/输出样例
题目输入
no input needed
题目输出
1 46 53 2 42 56 3 38 59 4 34 62 5 30 65 6 26 68 7 22 71 8 18 74 9 14 77 10 10 80 11 6 83 12 2 86 12
C语言解答
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <time.h> int main() { // freopen("in","r",stdin); // freopen("out","w",stdout); int x, y, z, count = 0; for (x = 1; x <= 28; x++) { for (y = 1; y <= 73; y++) { z = 100 - x - y; if (5*x + 2*y + z == 150) { count++; printf("%d %d %d\n", x, y, z); } } } printf("%d\n", count); return 0; }
C++解答
#include<stdio.h> int main() { int i,j,k,m,cunter = 0; for(i = 1;i <=12;i++) { for(j = 1;j <= 46;j++) { k = 150 - 5*i - 2*j; if((i + j < 100) && (5*i + j*2 + k == 150) && k < 100 && (i + j + k) == 100) { printf("%d %d %d\n",i,j,k); cunter++; } } } printf("%d\n",cunter); return 0; }