Codeforces 4A C++ Solution
Problem Link
Remarks:
Remarks:
- First, we want to make sure that the weight of the watermelon (w) is even. If the weight is not even, that it is impossible to satisfy the condition where the divided two parts would weigh even kilos. Therefore, we would print out "NO" if the weight is odd.
- In the case that the weight of the watermelon (w) is indeed even, then we use nested for loops. The loops are set up in this way because we want to deal with only even numbers and we want to brute force the solution.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int w; | |
cin >> w; | |
if (w % 2 == 0) { | |
for (int i = 2; i % 2 == 0 && i < w; i+=2) { | |
for (int j = 2; j % 2 == 0 && j < w; j+=2) { | |
if (w == i + j) { | |
cout << "YES" << endl; | |
return 0; | |
} | |
} | |
} | |
cout << "NO" << endl; | |
} else { | |
cout << "NO" << endl; | |
} | |
} |