Question A
Very simple and naive question. One thing worth noticing is that .
int main(){
int sum = 0;
int tp;
for(int i = 0; i < 5; ++ i){
cin >> tp;
sum += tp;
}
if (sum%5 == 0 && sum)
cout << sum/5 << endl;
else
cout << -1 << endl;
return 0;
}
Question B
It is not hard to guess the two extreme cases with minimum and maximum number of relationship. For minimum number of relationships, we strive to distribute all n
people to m
groups. For maximum number of relationships, we should try our best to centralize all people in one group. Then the computation is trivial. One important thing is that n
can be , which results in a very large number of relationships. Thus we should use long long
(even double fails because of precision..).
int main(){
long long n, m;
cin >> n >> m;
long long mx = (n-m+1)*(n-m)/2;
long long mod = n%m;
long long quo = n/m;
long long mi = (m-mod) * (quo * (quo-1))/2 + mod * (quo * (quo+1))/2;
printf("%I64d %I64d\n", mi, mx);
return 0;
}
Question C
The solution to this problem is a greedy solution, which is very short. The restriction is that we cannot have three balloons with the same color at the same table.
The key ideas are
- As every table has three balloons, the number of the table must be lower than
- We cannot have a number of tables that exceeds any of , , or . This is because, for example, if there is an additional table besides the tables, this table must be of three blue balloons
int main()
{
long long r,g,b;
cin>>r>>g>>b;
cout << min(min(min((r+g+b)/3,r+g),g+b),r+b);
}
Question D
This is a DP problem. I have not figured it out yet. To be continued…