はまやんはまやんはまやん

hamayanhamayan's blog

Task Scheduling Problem [AtCoder Beginner Contest 103 A]

https://beta.atcoder.jp/contests/abc103/tasks/abc103_a

解法

https://beta.atcoder.jp/contests/abc103/submissions/2885199

3個のタスクの実行順番を全探索する。
3!=6なので十分間に合う。
順列の全探索はnext_permutation関数を使うと良い。

int A[3];
//---------------------------------------------------------------------------------------------------
void _main() {
    rep(i, 0, 3) cin >> A[i];
 
    int ans = inf;
 
    vector<int> ord;
    rep(i, 0, 3) ord.push_back(i);
    do {
        int a = A[ord[0]], b = A[ord[1]], c = A[ord[2]];
        int ab = abs(a - b);
        int bc = abs(b - c);
        chmin(ans, ab + bc);
    } while (next_permutation(all(ord)));
 
    cout << ans << endl;
}