您的位置:首页 > 其它

CF #273 (Div. 2) A.(简单规律)

2014-10-17 12:31 281 查看
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 of
b, 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.

解题思路:

题意没看明白,只是把Note的操作看了一遍。就是一个求5个数的和,然后判断下sum 能否整除5。如果能整除的话,那么输出商,否则输出-1.

这里特判下5个数全为0的情况,此时应输出-1,因为要求b > 0,所以b = 0被视为不合法情况。

完整代码:

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <climits>
#include <cassert>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;

#pragma comment(linker, "/STACK:102400000,102400000")

typedef long long LL;
typedef double DB;
typedef unsigned uint;
typedef unsigned long long uLL;

/** Constant List .. **/ //{

const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const DB EPS = 1e-9;
const DB OO = 1e20;
const DB PI = acos(-1.0); //M_PI;

int a[5];
int main()
{
    #ifdef DoubleQ
    freopen("in.txt","r",stdin);
    #endif
    for(int i = 0 ; i < 5 ; i ++)
        scanf("%d",&a[i]);
    LL sum = 0;
    for(int i = 0 ;i < 5 ; i ++)
        sum += a[i];
    if(sum == 0)
        printf("-1\n");
    else if(sum % 5 == 0)
        printf("%lld\n",sum / 5);
    else
        printf("-1\n");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: