设为首页 加入收藏

TOP

Codeforces Round #273 (Div. 2)(一)
2015-07-20 17:26:30 来源: 作者: 【 】 浏览:8
Tags:Codeforces Round #273 Div.

?

?

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

There are five people playing a game called Generosity. Each person gives some non-zero number of coinsb as an initial bet. After all players make their bets ofb 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 sizeb of the initial bet or find out that such outcome of the game cannot be obtained for any positive number of coinsb in the initial bet.

Input

The input consists of a single line containing five integersc1,?c2,?c3,?c4 andc5 — 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 integerb — 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).

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:

One coin is passed from the fourth player to the second player;One coin is passed from the fourth player to the fifth player;One coin is passed from the first player to the third player;One coin is passed from the fourth player to the second player.

分析: 签到,注意0的时候特判-1

?

?

#include 
  
   
int main()
{
    int a, b, c, d, e;
    scanf(%d %d %d %d %d, &a, &b, &c, &d, &e);
    int sum = a + b + c + d + e;
    if(sum == 0)
        printf(-1
);
    else if(sum % 5 == 0)
        printf(%d
, sum / 5);
    else
        printf(-1
);
}
  

?

?

?

?

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

n participants of the competition were split intom 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 integerskmin andkmax — 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 of2 people, maximum number can be achieved if participants were split on teams of1, 1 and 4 people.


?

分析: 贪心,最大值显然是n-m+1人为一组,最小值则是尽可能均分,均分的话将余数均分分别加到商上即可

?

?

#include 
  
   
#define ll long long

ll cal(ll x)
{
    return x * (x - 1) / 2;
}

int main()
{
    ll n, m;
    ll ma, mi;
    scanf(%I64d %I64d, &n, &m);
    ma = cal(n - m + 1);
    ll tmp = n % m;
    ll a = n / m;
    ll num = 0;
    if(tmp == 0)
        mi = m * cal(a);
    else
        mi = tmp * cal(a + 1) + (m - tmp) * cal(a);
    printf(%I64d %I64d
, mi, ma);
}
  

?

?

?

?

C. Table Decorations time limit per test 1 second memory limit per test 2
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++基础之详解this指针(有,或者.. 下一篇UVA 1619 Feel Good(DP)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Python爬虫教程(从 (2025-12-26 16:49:14)
·【全269集】B站最详 (2025-12-26 16:49:11)
·Python爬虫详解:原 (2025-12-26 16:49:09)
·Spring Boot Java: (2025-12-26 16:20:19)
·Spring BootでHello (2025-12-26 16:20:15)