编程介的小学生 2019-03-08 16:15 采纳率: 20.5%
浏览 435

分段函数的求和寻找极值的一个问题,如何采用C语言的办法实现编程计算

Problem Description
It is well known, that the year on planet Eisiem has n days. Of course, some days are very good for people, while some others are just horrible. Long observations have shown for each day of the year whether this day is good for most people, or bad.

The new president of the Planet Federation wants all people to be happy. He knows that good emotions have a tendency to accumulate, just like bad ones do. The New Year however is a special event and all emotions accumulated by this moment just disappear. Therefore the president wants to change the calendar on Eisiem and choose the new first day of the year, so that the positive emotions would prevail the whole year.

More precisely, for all i from 1 to n let ai be 1 if i-th day is good for most people and -1 if it is bad. Let sjk be the sum of ai for all days from the j-th day of the year to the k-th, that is:

President wants to find such j to order the j-th day to be the first day of the year, that sjk is positive for all k from 1 to n. Since he wants several variants to choose from, he asks you to find all such j. Since he doesn't want to get too much information at once, first of all he wants to know the number of such j. That is exactly your task.

Input
The input contains multiple test cases. The first line of the input is a single integer T (1 <= T <= 30) which is the number of test cases. T test cases follow, each preceded by a single blank line.

The first line of each test case contains n - the number of days (1 <= n <= 200 000). Next line contains n integer numbers - ai.

Output
For each case, output the number of different indices j, such that sjk is positive for all k, in a single line.

Sample Input
2

5
1 -1 1 -1 1
7
1 1 1 1 1 1 1

Sample Output
1
7

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题