【CODEFORCES】 A. Initial Bet
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 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.
题解:加起来看能不能除5除的尽即可。
注意sum==0的时候也要输出-1。
#include <iostream>
#include <cstring>
#include <cstdio> using namespace std; int a,sum; int main()
{
for (int i=1;i<=5;i++)
{
scanf("%d",&a);
sum+=a;
}
if (sum==0) printf("-1\n");
else if (sum%5==0) printf("%d\n",sum/5);
else printf("-1\n");
return 0;
}
【CODEFORCES】 A. Initial Bet的更多相关文章
- 【Codeforces】Round #491 (Div. 2) 总结
[Codeforces]Round #491 (Div. 2) 总结 这次尴尬了,D题fst,E没有做出来.... 不过还好,rating只掉了30,总体来说比较不稳,下次加油 A:If at fir ...
- 【Codeforces】Round #488 (Div. 2) 总结
[Codeforces]Round #488 (Div. 2) 总结 比较僵硬的一场,还是手速不够,但是作为正式成为竞赛生的第一场比赛还是比较圆满的,起码没有FST,A掉ABCD,总排82,怒涨rat ...
- 【CodeForces】601 D. Acyclic Organic Compounds
[题目]D. Acyclic Organic Compounds [题意]给定一棵带点权树,每个点有一个字符,定义一个结点的字符串数为往下延伸能得到的不重复字符串数,求min(点权+字符串数),n&l ...
- 【Codeforces】849D. Rooter's Song
[算法]模拟 [题意]http://codeforces.com/contest/849/problem/D 给定n个点从x轴或y轴的位置p时间t出发,相遇后按对方路径走,问每个数字撞到墙的位置.(还 ...
- 【CodeForces】983 E. NN country 树上倍增+二维数点
[题目]E. NN country [题意]给定n个点的树和m条链,q次询问一条链(a,b)最少被多少条给定的链覆盖.\(n,m,q \leq 2*10^5\). [算法]树上倍增+二维数点(树状数组 ...
- 【CodeForces】925 C.Big Secret 异或
[题目]C.Big Secret [题意]给定数组b,求重排列b数组使其前缀异或和数组a单调递增.\(n \leq 10^5,1 \leq b_i \leq 2^{60}\). [算法]异或 为了拆位 ...
- 【CodeForces】700 D. Huffman Coding on Segment 哈夫曼树+莫队+分块
[题目]D. Huffman Coding on Segment [题意]给定n个数字,m次询问区间[l,r]的数字的哈夫曼编码总长.1<=n,m,ai<=10^5. [算法]哈夫曼树+莫 ...
- 【CodeForces】906 D. Power Tower 扩展欧拉定理
[题目]D. Power Tower [题意]给定长度为n的正整数序列和模数m,q次询问区间[l,r]累乘幂%m的答案.n,q<=10^5,m,ai<=10^9. [算法]扩展欧拉定理 [ ...
- 【CodeForces】741 D. Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths(dsu on tree)
[题意]给定n个点的树,每条边有一个小写字母a~v,求每棵子树内的最长回文路径,回文路径定义为路径上所有字母存在一种排列为回文串.n<=5*10^5. [算法]dsu on tree [题解]这 ...
随机推荐
- 【转载】SQL server connection KeepAlive
1.什么是SQL server TCP连接的keep Alive? 简单说,keep alive 是SQL server在建立每一个TCP 连接的时候,指定了TCP 协议的keepaliveinter ...
- poj2184
Cow Exhibition Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13578 Accepted: 5503 D ...
- Hibernate 快速上手操作入门
本文主要是从技术操作角度去介绍hibernate,并且简单描述如何快速的上手操作hibernate,用于作为与数据库的连接的持久层. 简单讲述一下hibernate究竟是什么,它有什么作用,在理解它的 ...
- kuangbin系列【简单搜索】
poj-1321棋盘问题[bfs/回溯] Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 36385 Accepted: ...
- ZOJ 3940 Modulo Query (2016年浙江省赛E题,区间折叠 + map运用)
题目链接 2016 ZJCPC Problem E 考虑一个开区间$[0, x)$对$a_{i}$取模的过程. $[0, x)$中小于$a_{i}$的部分不变,大于等于$a_{i}$的部分被切下来变 ...
- ASP.NET基础题(1-10)
1.简述 private. protected. public. internal 修饰符的访问权限. private : 私有成员, 在类的内部才可以访问. protected : 保护成员,该类内 ...
- [POI2010]Beads
题目大意: 给定一个长度为$n(n\leq200000)$的串$S_{1\sim n}$,选择一个$l$,从$S_1$开始,将$S$分为连续的若干段,使得每一段长度为$l$.令$k$为分出来不同的子串 ...
- 【转】MySQL5.5的my.cnf 参数详解
这篇文章很多地方只是翻译了my.cnf原始配置文件的说明 以下原文中有些参数事实上不适用于MySQL5.5,不知道原作者是否有经过实际测试,比如log-slow-queries应该写成slow-que ...
- 全面理解java自动装箱和拆箱(转)
自动装箱和拆箱从Java 1.5开始引入,目的是将原始类型值转自动地转换成对应的对象.自动装箱与拆箱的机制可以让我们在Java的变量赋值或者是方法调用等情况下使用原始类型或者对象类型更加简单直接. 如 ...
- Console-算法:fun1(do while)
ylbtech-Arithmetic:Console-算法[do while]-XX 1.A,Demo(案例) 1.B,Solution(解决方案) using System; namespace ...