codeforces round # 273 div2 A, B, C题题解

A. Initial Bet
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one player to some other player.

Your task is to write a program that can, given the number of coins each player has at the end of the game, determine the size b of the initial bet or find out that such outcome of the game cannot be obtained for any positive number of coins b in the initial bet.

Input

The input consists of a single line containing five integers c1, c2, c3, c4 and c5 — the number of coins that the first, second, third, fourth and fifth players respectively have at the end of the game (0 ≤ c1, c2, c3, c4, c5 ≤ 100).

Output

Print the only line containing a single positive integer b — the number of coins in the initial bet of each player. If there is no such value of b, then print the only value "-1" (quotes for clarity).

Sample test(s)
Input
2 5 4 0 4
Output
3
Input
4 5 9 2 1
Output
-1
Note

In the first sample the following sequence of operations is possible:

  1. One coin is passed from the fourth player to the second player;
  2. One coin is passed from the fourth player to the fifth player;
  3. One coin is passed from the first player to the third player;
  4. One coin is passed from the fourth player to the second player.


水题,但是有个坑点,如果5个数都是0,要输出-1而不是0


#include <map>
#include <set>
#include <list>
#include <stack>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>


using namespace std;

int main()
{
    int a, b, c, d, e;
    while (~scanf("%d%d%d%d%d", &a, &b, &c, &d, &e))
    {
        int sum = a + b + c + d + e;
        if(sum % 5 != 0 || sum == 0)
        {
            printf("-1\n");
            continue;
        }
        printf("%d\n",  sum / 5);
    }
    return 0;
}

B. Random Teams
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

n participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.

Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.

Input

The only line of input contains two integers n and m, separated by a single space (1 ≤ m ≤ n ≤ 109) — the number of participants and the number of teams respectively.

Output

The only line of the output should contain two integers kmin and kmax — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.

Sample test(s)
Input
5 1
Output
10 10
Input
3 2
Output
1 1
Input
6 3
Output
3 6
Note

In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.

In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.

In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people.


最多的话,就是m-1组放1个人,最后那组放n - m + 1个人

最少的话,就是平摊


#include <map>
#include <set>
#include <list>
#include <stack>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>


using namespace std;

int main()
{
    __int64 n, m;
    while (~scanf("%I64d%I64d", &n, &m))
    {
        __int64 mins = 0;
        __int64 cnt = n / m;
        if(n % m == 0)
        {
            mins = m * (cnt - 1) * cnt / 2;
        }
        else
        {
            int lst = n % m;
            mins = lst * (cnt + 1) * cnt / 2 + ( m - lst) * (cnt - 1) * cnt / 2;
        }
        __int64 maxs = (n - m + 1) * ( n - m) / 2;
       printf("%I64d %I64d\n", mins, maxs);
    }
    return 0;
}


C. Table Decorations
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number t of tables can be decorated if we know number of balloons of each color?

Your task is to write a program that for given values r, g and b will find the maximum number t of tables, that can be decorated in the required manner.

Input

The single line contains three integers r, g and b (0 ≤ r, g, b ≤ 2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space.

Output

Print a single integer t — the maximum number of tables that can be decorated in the required manner.

Sample test(s)
Input
5 4 3
Output
4
Input
1 1 1
Output
1
Input
2 3 3
Output
2
Note

In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively.


贪心题,第二轮挂了,做法参照网上


#include <map>
#include <set>
#include <list>
#include <stack>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>


using namespace std;

int cmp(__int64 a, __int64 b)
{
    return a < b;
}

int main()
{
    __int64 a[3];
    while (~scanf("%I64d%I64d%I64d", &a[0], &a[1], &a[2]))
    {  
        sort(a, a + 3, cmp);
        __int64 x = a[0];
        __int64 y = a[1];
        __int64 z = a[2];
        if(x * 2 + y * 2 <= z)
        {
            printf("%I64d\n", x + y);
            continue;
        }
        printf("%I64d\n", (x + y + z) / 3);
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值