A- Construct a Rectangle Codeforces Educational Round 120
Approach-
The idea is to take the given lengths in increasing order. And the solution is only possible when the difference of the largest and the smallest value is equal to the middle value, so that the largest one can be broken in two pieces. Or if any two lengths are equal and the third one is divisible by 2 (to get integer length on cutting), the answer is yes. Only these four cases will have a positive answer.
Below is the detailed code in C++ exactly matching with the explanation above.
Code-
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(ii, n) for (ll ii = 0; ii < n; ii++)
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll testcase=1;
cin >> testcase;
f(i, testcase)
{
ll n=3;
ll a[n];
f(i,n)
cin>>a[i];
sort(a, a+n);
if(a[2]-a[0]==a[1])
cout<<"YES"<<endl;
else if((a[0]==a[1]&&a[2]%2==0)||(a[2]==a[1]&&a[0]%2==0)||(a[0]==a[2]&&a[1]%2==0))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
}
Other Problems from this Contest-
Disclaimer- Everything is published after the actual contest gets over.
Comments