Codeforces Round #273 (Div. 2) 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 ofb, then print the only value "-1" (quotes for clarity).

Examples
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.

题意:求整数平均数,并且平均数>0;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=1e5+10,M=4e6+10,inf=1e9+10;
const ll INF=1e18+10;
int main()
{
    int sum=0;
    for(int i=1;i<=5;i++)
    {
        int x;scanf("%d",&x),sum+=x;
    }
    if(sum%5||sum==0)
    printf("-1\n");
    else
    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.

Examples
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 2people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people.

题意:n个人,m支队,将n个人分到m支队,每个队最少一个人,每个队内的人相互认识,但是不认识别的队的人,求分配认识对数,最小和最大;

思路:最小显然平均分配,最大显然是将(m-1)支队分到一个人,另外一只分n-m+1个人;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=1e5+10,M=4e6+10,inf=1e9+10;
const ll INF=1e18+10;
ll getans(ll x)
{
    return x*(x-1)/2;
}
int main()
{
    ll n,m;
    scanf("%lld%lld",&n,&m);
    ll minn=getans(n/m+(n%m?1:0))*(n%m?n%m:m)+getans(n/m)*((m-(n%m))%m);
    ll maxx=getans(n-m+1);
    printf("%lld %lld\n",minn,maxx);
    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 rg 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 rg 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.

Examples
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.

 题意:有r个红气球,g个绿气球,b个蓝气球,每张桌子的三个气球不能同色,问r,g,b最多能装多少张桌子;

思路:贪心,判断是否有极端,否则相加除3;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
const int N=1e5+10,M=4e6+10,inf=1e9+10;
const ll INF=1e18+10;
ll a[10];
int main()
{
    scanf("%lld%lld%lld",&a[0],&a[1],&a[2]);
    sort(a,a+3);
    if(a[2]>2*a[0]+2*a[1])
    printf("%lld\n",a[0]+a[1]);
    else
    printf("%lld\n",(a[0]+a[1]+a[2])/3);
    return 0;
}

 

 

转载于:https://www.cnblogs.com/jhz033/p/5854391.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值