题解:P15021 [UOI 2020 II Stage] 方程

· · 题解

P15021 [UOI 2020 II Stage] 方程

solution

枚举一下,总共有 3 \times 2 \times 1 = 6 种正确的方案,如果给出的数都不满足这六种,那么就是无解的情况,输出 -1 -1 -1

做完了。

AC code

#include <bits/stdc++.h>
#define debug(a) cerr << (#a) << " = " << (a) << endl;
#define int long long
#define maxn 100010
#define endl '\n'
using namespace std;

int x, y, z, k;
void solve() {
    if (x * x * x + y * y + z == k) {
        cout << x << " " << y << " " << z << endl;
    }
    else if (x * x * x + z * z + y == k) {
        cout << x << " " << z << " " << y << endl;
    }
    else if (y * y * y + x * x + z == k) {
        cout << y << " " << x << " " << z << endl;
    }
    else if (y * y * y + z * z + x == k) {
        cout << y << " " << z << " " << x << endl;
    }
    else if (z * z * z + x * x + y == k) {
        cout << z << " " << x << " " << y << endl;
    }
    else if (z * z * z + y * y + x == k) {
        cout << z << " " << y << " " << x << endl;
    }
    else {
        cout << "-1 -1 -1" << endl;
    }
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t; t = 1;
    while (t--) {
        cin >> x >> y >> z >> k;
        solve();
    }
    return 0;
}