A. Initial Bet(Codeforces Round #273)
1 second
256 megabytes
standard input
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.
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 of b,
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.
#include <iostream>
#include <cstdio>
using namespace std; int main()
{
int a[10];
int ans=0;
for(int i=0;i<5;i++)
{
scanf("%d",&a[i]);
ans+=a[i];
}
if(ans==0)
{
printf("-1\n");
return 0;
}
if(ans%5==0)
printf("%d\n",ans/5);
else
printf("-1\n");
return 0;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
A. Initial Bet(Codeforces Round #273)的更多相关文章
- 贪心 Codeforces Round #273 (Div. 2) C. Table Decorations
题目传送门 /* 贪心:排序后,当a[3] > 2 * (a[1] + a[2]), 可以最多的2个,其他的都是1个,ggr,ggb, ggr... ans = a[1] + a[2]; 或先2 ...
- Codeforces Round #273 (Div. 2)-A. Initial Bet
http://codeforces.com/contest/478/problem/A A. Initial Bet time limit per test 1 second memory limit ...
- Codeforces Round #273 (Div. 2)
A. Initial Bet 题意:给出5个数,判断它们的和是否为5的倍数,注意和为0的情况 #include<iostream> #include<cstdio> #incl ...
- Codeforces Round #273 (Div. 2) A , B , C 水,数学,贪心
A. Initial Bet time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- CODEFORCES ROUND #273 DIV2
题目大意: A简单的说就是,有五个人,他们刚开始有B元,经过一系列过程后,给你他们现在分别有的钱,让你求出B(> <难得的傻逼题啊...但是要注意B是正整数!特判0) B有n个人,要分成m ...
- Codeforces Round #273 (Div. 2)-C. Table Decorations
http://codeforces.com/contest/478/problem/C C. Table Decorations time limit per test 1 second memory ...
- Codeforces Round #273 (Div. 2)-B. Random Teams
http://codeforces.com/contest/478/problem/B B. Random Teams time limit per test 1 second memory limi ...
- C. Table Decorations(Codeforces Round 273)
C. Table Decorations time limit per test 1 second memory limit per test 256 megabytes input standard ...
- B. Random Teams(Codeforces Round 273)
B. Random Teams time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
随机推荐
- Latin1的所有字符编码
ISO-8859-1 (ISO Latin 1) Character Encoding Contents The characters at a glance Character codes and ...
- winform下载网页代码
1:webClient client=new WebClient(); client.Downloadstring(地址) client.Downloadfile(地址,保存路径) 2:后台线程dow ...
- 事件总线帧---Otto
我们如果这样一种业务场景.如今在做一款及时聊天应用,我们在聊天页面进行收发信息.同一时候也要实时更新前一页面的聊天记录,这时我们该怎样去实现?说说我曾经的实现策略.我使用的是广播接收器BroadCas ...
- Delphi过程函数传递参数的八种方式
今天一同事问我为什么有些过程函数里面有Var而有些没有,不解,遂到网上百度,得解.快哉,快哉. 在Delphi过程.函数中传递参数几个修饰符为Const.Var.Out.另一种不加修饰符的为默认按值传 ...
- 理解 Python 中的线程
原地址:http://blog.jobbole.com/52060/ 本文由 伯乐在线 - acmerfight 翻译自 Akshar Raaj.欢迎加入技术翻译小组.转载请参见文章末尾处的要求. 我 ...
- php学习之道:WSDL具体解释(三)
通过声明方式定义绑定(binding)属性 假设你在服务中採用SOAP binding.你能够使用JAX-WS来指定一定数量的属性binding. 这些属性指定相应你在WSDL中指定的属性.某些设置. ...
- Android在子线程中更新UI(一)
MainActivity如下: package cc.testui1; import android.os.Bundle; import android.os.Handler; import andr ...
- 从mina中学习超时程序编写
从mina中学习超时程序编写 在很多情况下,程序需要使用计时器定,在指定的时间内检查连接过期.例如,要实现一个mqtt服务,为了保证QOS,在服务端发送消息后,需要等待客户端的ack,确保客户端接收到 ...
- Spark技术内幕:Stage划分及提交源代码分析
当触发一个RDD的action后.以count为例,调用关系例如以下: org.apache.spark.rdd.RDD#count org.apache.spark.SparkContext#run ...
- JFinal开发8个常见问题
下面是8个最常见的问题总结. 1.Can not create instance of class: demo.DemoConfig. 觉得应该是你的路径有问题, 打开你项目的java build p ...