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
Output
Input
Output
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被视为不合法情况。
完整代码:
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"); }
相关文章推荐
- DIV+CSS 滑动门技术的简单例子
- 原创:使DIV标签居中的简单方法。FF1.07/IE6 测试通过
- [已封装] DIV拖动类 支持在FF下拖动,调用简单 主要代码都有注释 适合初学者学习
- [转]JavaScript简单实现div拖拽
- (简单的弹出div 覆盖背景)改善用户体验之alert提示效果 http://www.blueidea.com/tech/web/2006/4185.asp
- [转]JavaScript简单实现div拖拽
- js源码--简单的div拖动
- 几个css元素的简单解释 div ul dl dt ol
- 一个div遮照的简单实现
- DIV+CSS 网页TIP的简单作法
- js实现DIV的一些简单控制
- 对DIV的一些简单控制
- javascript之DIV拖动类 支持在FF下拖动,调用简单
- 研究Subsonic得到的副产品,一个简单的Modal DIV
- DIV+CSS 网页TIP的简单作法
- DIV+CSS 简单的导航条
- js实现DIV的一些简单控制
- 常用CSS元素div ul dl dt ol的简单解释
- 一个最简单的div循环流动示例
- 最简单的 DIV + Javascript 分页演示代码