A. Watermelon
Any weight that is even and greater than $$$2$$$ can be divided into two even numbers, say $$$2$$$ and $$$(w-2)$$$, And in other cases, splitting into two even weights is impossible.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int w;
cin>>w;
if(w%2==0 && w!=2)
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
return 0;
}
B. Division?
For this problem you just need to implement what it asks you. To be able to implement it you need to know about the "if" statement.
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for(int i=1; i<=t; ++i)
{
int x; cin >> x;
if(x < 1400) cout << "Division 4\n";
else if(x < 1600) cout << "Division 3\n";
else if(x < 1900) cout << "Division 2\n";
else cout << "Division 1\n";
}
}
C. Nauuo and Votes
Consider the two edge cases: all the $$$z$$$ persons upvote or all the $$$z$$$ persons downvote. If the results are the same in these two cases, it is the answer. Otherwise, the result is uncertain.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x, y, z;
cin>>x>>y>>z;
if(x>(y+z))
{
cout<<"+"<<endl;
}
else if(y>(x+z))
{
cout<<"-"<<endl;
}
else if(x==y && z==0)
{
cout<<"0"<<endl;
}
else
{
cout<<"?"<<endl;
}
}
D. Bear and Big Brother
In this problem just multiply $$$a$$$ by $$$3$$$ and $$$b$$$ by $$$2$$$ until $$$a$$$ > $$$b$$$. Output the number of operations.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a, b, i;
cin>>a>>b;
for(i=0; a<=b ;++i)
{
a=3*a;
b=2*b;
}
cout<<i;
return 0;
}
E. Little Artem and Presents
We need to make sequence of moves like: 1, 2, 1, 2, ...
So the answer is $$$2 * n / 3$$$. After that we have either 0, 1 or 2 stones left. If we have 0, we are done, otherwise we have 1 or 2 left, so we only can give 1 more stone.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
if(n % 3 == 0)
{
cout<<2 * (n / 3);
}
else
{
cout<<2 * (n / 3) + 1;
}
}
F. Display Size
We can iterate through the values of $$$a$$$ from $$$1$$$ to n. For each $$$i$$$ if $$$n$$$ is divisible by $$$i$$$ and if difference $$$(n/i$$$ — $$$i)$$$ is less than already found difference we need to update answer with values $$$i$$$ and $$$n/i$$$ (because $$$a$$$ must be less than $$$b$$$).
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a = 1;
int b = n;
int difference = (n-1);
for(int i=1; i<=n/2; ++i)
{
if(n%i==0)
{
if(i > n/i)
{
continue;
}
if(n/i - i < difference)
{
a = i;
b = n/i;
difference = n/i - i;
}
}
}
cout<<a<<" "<<b<<endl;
}