当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3678:Integer Game

题目描述
You are given a circle of numbers (it is guaranteed that the sum of all numbers will always be larger than zero), and as long as there is a negative number among them, you can perform the following operation:

Choose a negative number Y , and then change the adjacent two numbers, X and Z , to X + Y and Z + Y respectively, and after that you can change the negative number Y to a positive number - Y .

The game terminates when no negative number can be found. Since you want to play the game as long as possible, you wonder how to play the game so that the total number of operations will be maximized, or whether there's a way to make this game such that this game never terminate.
输入解释
There are multiple test cases in the input file. Each test case starts with one integer N (3<=N<=1000) , followed by N integers in the range [-1000, 1000] on the next line, describing the numbers on the circle in the clockwise direction. Two successive inputs are separated by a blank line. A single line with N = 0 indicates the end of input file.
输出解释
For each test case, output one integer on a separate line, the maximum number of possible operations, the output format should be as indicated in the sample output. If a sequence of operations exists satisfying the condition that the game will never terminate, output ``-1" instead.
输入样例
3 
1 -1 1 

5 
1 2 3 4 5 

0
输出样例
Case 1: 1 
Case 2: 0
来自杭电HDUOJ的附加信息
Recommend lcy

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-3678

最后修改于 2020-10-25T23:05:53+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
10000/5000MS(Java/Others) 32768/32768K(Java/Others)