A. Three Pairwise Maximums
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output
You are given three positive (i.e. strictly greater than zero) integers x, y and z.
Your task is to find positive integers a, b and c such that x=max(a,b), y=max(a,c) and z=max(b,c), or determine that it is impossible to find such a, b and c.
You have to answer t independent test cases. Print required a, b and c in any (arbitrary) order.
Input
The first line of the input contains one integer t (1≤t≤2⋅104) — the number of test cases. Then t test cases follow.
The only line of the test case contains three integers x, y, and z (1≤x,y,z≤109).
Output
For each test case, print the answer:
“NO” in the only line of the output if a solution doesn’t exist;
or “YES” in the first line and any valid triple of positive integers a, b and c (1≤a,b,c≤109) in the second line. You can print a, b and c in any order.
Example
inputCopy
5
3 2 3
100 100 100
50 49 49
10 30 20
1 1000000000 1000000000
outputCopy
YES
3 2 1
YES
100 100 100
NO
NO
YES
1 1 1000000000
题目大意:
给出 t 组测试样例,对于每组测试样例给出三个数x y z,你需要寻找三个数a, b, c使得x = max(a,b) y = max(a,c) z = max(b,c) 如果能找到则输出YES按任意顺序打印abc,如果找不到则输出NO;
解题思路:
如果要找到三个数abc,那么给出的xyz 从大到小排序后一定满足 x = y >= z才能找到abc,因为x y z都是由max(…)得来的,abc一定有一个最大,也就是说xyz至少有两个是相等的。这样就可以推出a的值,让a = x(y),剩下的那两个一定要小于等于最大的数,才能保证剩余的z能通过max得到。因为数据范围是1-1e9,所以让剩下的两个数都等于z即可,放止发生1-1 = 0 的情况。
AC代码:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
using namespace std;
const int N = 15;
typedef long long ll;
int main()
{
int n;
cin >> n;
while (n--)
{
ll a[5];
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 3, greater<ll >());
if (a[0] != a[1])
{
cout << "NO" << endl;
continue;
}
cout << "YES" << endl;
cout << a[0] << " " << a[2] << " " << a[2] << endl;
}
return 0;
}