当前位置:网站首页>Openjudge noi 1.13 13: RMB payment
Openjudge noi 1.13 13: RMB payment
2022-06-10 04:34:00 【Junyi_ noip】
【 Topic link 】
OpenJudge NOI 1.13 13: RMB payment
【 Topic test site 】
1. Division operation
2. Count array
【 Their thinking 】
This question uses the idea of greed , First, try to take large denomination currency to make a contribution , If you add a currency , The total amount of money is greater than the amount of money to be collected , Then choose a smaller currency to raise money .
Store the face value in the array from large to small a in .
solution 1: Use integer division
Traversal array a, The amount of money that needs to be collected at present is n, The face value concerned is a[i], The number of currencies with this face value is n/a[i], The amount of money left is n%a[i].
Give Way n Into the amount of money left , Look at the next currency with a smaller face value .
solution 2: Use count array
The face value of the current concern is a[i], Take one currency of that face value at a time , Until the denomination currency is used , The amount of money left is less than 0, Then look at the next currency with a smaller face value . Use the count array to record the number of each currency .
【 Solution code 】
solution 1: Use integer division
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n, a[6] = {
100, 50, 20, 10, 5, 1};
cin >> n;
for(int i = 0; i < 6; ++i)
{
cout << n/a[i] << endl;
n %= a[i];
}
return 0;
}
solution 2: Use count array
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n, i = 0, c[6] = {
}, a[6] = {
100, 50, 20, 10, 5, 1};
cin >> n;
while(n > 0)
{
if(n >= a[i])// If the rest of the money to be collected is greater than or equal to the current concerned face value
{
c[i]++;// The amount of currency with this face value plus 1
n -= a[i];
}
else
i++;
}
for(i = 0; i < 6; ++i)// Output the number of each currency
cout << c[i] << endl;
return 0;
}
边栏推荐
- 23 very useful shell scripts
- Celery | 任务队列神器
- 497. 非重叠矩形中的随机点
- Detailed explanation of selection experience of resistor capacitor packaging
- S系列·在已作出的matplotlib图中新增图例
- The relationship between libc, glibc and glib
- Yyds dry goods inventory solution sword finger offer: rectangular coverage
- FastApi-14-文件上传-2
- - Oui. Net C # Foundation (7): Interface - Comment les gens interagissent avec les chats
- Mnemonic search + state compression leetcode four hundred and sixty-four
猜你喜欢

TCP (sliding window, flow control)

Fastapi-16-page beautification-1

Final examination paper 2 of the first postgraduate course in Dialectics of nature

5 minutes to learn how to set up local pypi source

midway的使用教程

Log management of MySQL database

Email: analysis of wrong arrangement

Zero basic network: command line (CLI) debugging firewall practice

ThreadLocal not yet? Come and have a look!

Gevent | use it asynchronously!
随机推荐
OpenJudge NOI 1.13 13:人民币支付
Test concept
FastApi-17-页面美化-2
S系列·删除文件夹的几种姿势
常见的数据库-字段类型映射关系
GUI programming student achievement management system
Exemple de démarrage JDBC
ThreadLocal basic and advanced use
Basic methods of stack and related problems
.NET C#基础(7):接口 - 人如何和猫互动
[cloud native | kubernetes] in depth understanding of pod (VI)
FastApi-14-文件上传-2
golang学习之五:error、painc、recover
Pampy | 超强的模式匹配工具
这些编程语言老了,差不多死透了,年轻人不能碰
Golang learning 4: closures and defers
FastApi-16-页面美化-1
Gevent | use it asynchronously!
电阻电容封装选型经验详解
JDBC 入门示例