Description

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

Constraints

6n105

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?)