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).
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.
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=0,M=0,Z=1e9+7,ms63=1061109567;
int a[7];
int main()
{
int sum=0,x;
for(int i=1;i<=5;++i)
{
scanf("%d",&x);
sum+=x;
}
printf("%d\n",sum==0||sum%5?-1:sum/5);
return 0;
}
/*
【trick&&吐槽】
不好好读题,自然要吃一发WA
【题意】
5个人手里,初始都有b枚硬币,b为非负整数。
经过若干次打赌后,(每次打赌结果是一个人把自己有的一枚硬币给了另外一个人),告诉你每个人最后的硬币数。
依次告诉你这5个人最后的硬币数a[],(0<=a[]<=100)。
让你判定是否可能存在一个合法的初始条件。
如果合法,输出b。如果不合法,输出-1。
【类型】
水题 语文题
【分析】
首先,b肯定只能是sum/5,所以我们要求出sum,查看sum是否是5的倍数。
如果不是显然-1.否则答案就是sum/5.
错!
虽然c[]都非负,但是c[]是可能为0的,所以我们可能会算得b==0。
于是这里也要判定为-1.
*/