Algoogle

Algorithm for Programming Contest

AOJ 2216 Summer of KMC

Category: AOJ Tag: greedy

Summer of KMC

問題概要


解法


greedyにやればよい

コード


(2216.cpp) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <bits/stdc++.h>
#define rep(i, b) for(int i = 0; i < b; i++)
using namespace std;

int c[3] = {1000,500,100};

int main(){
    int a, b;
    while(cin >> a >> b, a || b){
        int n = b - a;
        int ans[3] = {0};
        rep(i,3){
            while(n/c[i]){
                n -= c[i];
                ans[i]++;
            }
        }
        cout << ans[2] << ' ' << ans[1] << ' ' << ans[0] << endl;
    }
}

Comments