编程介的小学生 2017-02-13 09:49 采纳率: 20.5%
浏览 873
已采纳

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.
输出:

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.
样例输入:

3
1 -1 1

5
1 2 3 4 5

0
样例输出:

Case 1: 1
Case 2: 0

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-02-13 10:14
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有偿求码,CNN+LSTM实现单通道脑电信号EEG的睡眠分期评估
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路