-
Notifications
You must be signed in to change notification settings - Fork 0
/
squaredeal.cpp
94 lines (82 loc) · 2.62 KB
/
squaredeal.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <bits/stdc++.h>
using namespace std;
// Used to sort pairs based on their first number, followed by their second
bool Compare(pair<int, int> &a, pair<int, int> &b)
{
if(a.first == b.first)
{
return a.second < b.second;
}
else
{
return a.first < b.first;
}
}
int main()
{
vector<pair<int, int>> ps; // Vector of the pieces
// Get all the pieces
for(int i = 0; i < 3; i++)
{
int a, b;
cin >> a >> b;
ps.push_back(make_pair(max(a,b), min(a,b)));
}
// Sort the pieces in descending order
sort(ps.begin(), ps.end());
reverse(ps.begin(), ps.end());
// Store the piece with the longest side in m, and the 2 smaller pieces
// in a and b
pair<int, int> m = *ps.begin();
pair<int, int> a = *(ps.begin()+1);
pair<int, int> b = *(ps.begin()+2);
// Get the long and short side of the piece with the longest side
int l = max(m.first, m.second);
int s = min(m.first, m.second);
// If the sum pairs of side lengths for the vertical and horizontal sides of the other 2 pieces
// aren't equal to the longest side of m, or pair of side lengths aren't both equal to the longest side of m
if(a.first + b.first != l && a.second + b.second != l && (a.first != m.first && b.first != m.first))
{
// Switch the vertical and horizontal sides of piece a
int t = a.first;
a.first = a.second;
a.second = t;
}
int d; // The amount to add to the shortest side to get towards l
// If the longest side of a and b are equal to l
if(a.first == b.first && b.first == l)
{
// The amount to add is the sum of their shorter sides
d = a.second + b.second;
}
// If the first sides of a and b are equal to l and the other sides are the same length
else if(a.first + b.first == l && a.second == b.second)
{
// The amount to add is the other side length
d = a.second;
}
// If the second sides of a and b are equal to l and the other sides are the same length
else if(a.second + b.second == l && a.first == b.first)
{
// The amount to add is the other side length
d = a.first;
}
// If 2 sides can't be added to get to size l, or the other sides don't match so
// don't create a rectangle
else
{
cout << "NO" << endl;
return 0;
}
// If you can get to l by adding the amount to the shortest side
if(l == s+d)
{
cout << "YES" << endl;
}
// If you can't get to l by adding the amount to the shortest side
else
{
cout << "NO" << endl;
}
return 0;
}