题目描述
这道题还是有点难度的需要掌握贪心算法
样例
#include<iostream>
using namespace std;
int main() {
int N;
cin >> N;
cout<<N<<endl;
const int qianleizongshu = 7;
int qianzhong[qianleizongshu] = { 100,50,20,10,5,2,1 };
int meizhongqianshuliang[qianleizongshu] = { 0 };
for (int i = 0; i < qianleizongshu && N>0; i++) {
meizhongqianshuliang[i] = N / qianzhong[i];
N -= meizhongqianshuliang[i] * qianzhong[i];
}
for (int i = 0; i < qianleizongshu; i++) {
cout << meizhongqianshuliang[i] << " nota(s) de R$ " << qianzhong[i] <<",00"<< endl;
}
return 0;
}
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla