九度 oj 题目1549:货币问题

    xiaoxiao2021-03-25  128

    http://ac.jobdu.com/problem.php?pid=1549

    参考了http://www.voidcn.com/blog/newchan/article/p-4594278.html

    贪心,用大面值肯定比用小面值 张数少

    #include <cstdio> #include <algorithm> #include <cstring> using namespace std; #define ms(x,y) memset(x,y,sizeof(x)) #define inone(i) scanf("%d",&i) #define rep(i,j,k) for(int i=j;i<=k;i++) #define per(i,j,k) for(int i=k;i>=j;i--) const int a[7] = { 1,2,5,10,20,50,100 }; int n, cnt; int main() { while (inone(n) != EOF) { cnt = 0; per(i, 0, 6) { cnt += n / a[i]; n %= a[i]; } printf("%d\n", cnt); } return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-7593.html

    最新回复(0)