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.
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).
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).
2 5 4 0 4
3
4 5 9 2 1
-1
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;
#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 "); else printf("%d ",sum/5); return 0; }
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.
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.
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.
5 1
10 10
3 2
1 1
6 3
3 6
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 ",minn,maxx); return 0; }