Home Codeforces-1690A Print a Pedestal (Codeforces logo?)
Post
Cancel

Codeforces-1690A Print a Pedestal (Codeforces logo?)

Description

给定\(n\),求构造\(x + y + z = n\),其中\(x \gt y \gt z \gt 0\),要求\(x\)尽可能小,答案输出\(y, x, z\)。

Constraints

\(6 \le n \le 10^5\)

Solution

很显然要将三个数往\(n/3\)靠拢。观察\(n \% 3 = m\)的情况,在总和上补齐\(m\)即可,解法不唯一。

Code

#include <bits/stdc++.h>
using namespace std;

int main() {
    int t; cin >> t;
    while(t--) {
        int n; cin >> n;
        int x, y, z;
        if(n % 3 == 0) {
            x = n / 3 + 1;
            y = n / 3;
            z = n / 3 - 1;
        } else if(n % 3 == 1) {
            x = n / 3 + 2;
            y = n / 3;
            z = n / 3 - 1;
        } else {
            x = n / 3 + 2;
            y = n / 3 + 1;
            z = n / 3 - 1;
        }
        cout << y << ' ' << x << ' ' << z << endl;
    }
}

Codeforces-1690A Print a Pedestal (Codeforces logo?)

This post is licensed under CC BY 4.0 by the author.
Contents