【Codeforces Round 273 (Div 2)A】【水题 语文题】 Initial Bet 5人初始硬币都为b,告诉你最后的硬币数让你输出合法正整数b

这是一个名为'Generosity'的游戏,五名玩家初始投入非零硬币数b。游戏结束后,给你每位玩家的硬币数,你需要找出可能的初始投入硬币数b,或表明无法通过任何正整数b获得这种结果。
摘要由CSDN通过智能技术生成

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

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.


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

*/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值