题解:硬币面值组合

硬币面值组合

时间限制:1秒        内存限制:128M

题目描述

使用1角、2角、5角硬币组成 n 角钱。设1角、2角、5角的硬币各用了a、b、c个,列出所有可能的a, b, c组合。输出顺序为:先按c的值从小到大,若c相同则按b的值从小到大。

输入描述

一个整数n(1 <= n <= 100),代表需要组成的钱的角数。

输出描述

输出有若干行,每行的形式为: i a b c 第1列i代表当前行数(行数从001开始,固定3个字符宽度,宽度不足3的用0填充),后面3列a, b, c分别代表1角、2角、5角硬币的个数(每个数字固定12个字符宽度,宽度不足的在左边填充空格)。

样例

输入

10

输出

001          10           0           0
002           8           1           0
003           6           2           0
004           4           3           0
005           2           4           0
006           0           5           0
007           5           0           1
008           3           1           1
009           1           2           1
010           0           0           2

 这题非常简单,直接打暴力就行了

那就废话不多说,不多说废话,因为说废话真的很烦,也不知道大家喜不喜欢话说废话,不过我是从不说废话的,那我们上AC代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<list>
using namespace std;
int main(){
    int n,ans=1,i,j,k;
    cin>>n;
    for(i=0;i<=n/5;i++){
        for(j=0;j<=n/2;j++){
            for(k=0;k<=n;k++){
                if(i*5+j*2+k==n){
                    printf("%03d",ans);
                    ans++;
                    printf("%12d%12d%12d\n",k,j,i);
                }
            }
        }
    }
    return 0;
}


好了!

下篇博文见!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
你好!对于扫雷游戏的题解,我可以给你一些思路和代码示例。首先,你需要了解扫雷游戏的规则和要求。接下来,你可以使用C++语言来实现游戏逻辑和界面。 下面是一个简单的扫雷游戏的C++代码示例: ```cpp #include <iostream> #include <vector> #include <random> using namespace std; class MinesweeperGame { private: int rows; int cols; vector<vector<char>> board; vector<vector<bool>> revealed; vector<pair<int, int>> directions = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}}; public: MinesweeperGame(int m, int n, int mineCount) { rows = m; cols = n; board.resize(rows, vector<char>(cols, ' ')); revealed.resize(rows, vector<bool>(cols, false)); placeMines(mineCount); calculateNumbers(); } void printBoard() { cout << " "; for (int j = 0; j < cols; j++) { cout << j << " "; } cout << endl; for (int i = 0; i < rows; i++) { cout << i << " |"; for (int j = 0; j < cols; j++) { cout << board[i][j] << "|"; } cout << endl; } } bool isGameOver() { for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { if (board[i][j] == 'M' && revealed[i][j]) { return true; } } } return false; } void reveal(int row, int col) { if (row < 0 || row >= rows || col < 0 || col >= cols || revealed[row][col]) { return; } revealed[row][col] = true; if (board[row][col] == 'M') { return; } if (board[row][col] == '0') { for (auto dir : directions) { reveal(row + dir.first, col + dir.second); } } } private: void placeMines(int mineCount) { random_device rd; mt1

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值