CSU 1203 Super-increasing sequence (模拟)

1203: Super-increasing sequence

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 251  Solved: 91
[ Submit][ Status][ Web Board]

Description

如果一个序列中任意一项都大于前面所有项之和,那么我们就称这个序列为超递增序列。

现在有一个整数序列,你可以将序列中任意相邻的若干项合并成一项,合并之后这项的值为合并前各项的值之和。通过若干次合并,最终一定能得到一个超递增序列,那么得到的超递增序列最多能有多少项呢?

Input

输入数据的第一行包含正整数T (1 <= T <= 500),表示接下来一共有T组测试数据。

每组测试数据的第一行包含一个整数N (1 <= N <= 100000),表示这个整数序列一共有N项。接下来一行包含N个不大于10000的正整数,依次描述了这个序列中各项的值。

至多有10组数据满足N > 1000

Output

对于每组测试数据,用一行输出一个整数,表示最终得到的超递增序列最多能有多少项。

Sample Input

3
2
1 1
3
1 2 4
6
1 2 4 3 6 5

Sample Output

1
3
4

HINT

Source


思路:

简单模拟

注意:

大于前面所有项之和,而不是大于前一合并项之和。


/*************************************************************************
	> File Name: C.cpp
	> Author: BSlin
	> Mail:  
	> Created Time: 2013年10月03日 星期四 14时33分41秒
 ************************************************************************/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iterator>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#define MP make_pair
#define INF (1<<30)
#define PI acos(-1.0)
#define esp 1e-8
const int dx[4]={0,0,0,0};
using namespace std;
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
#if defined (_WIN32) || defined (__WIN32) || defined (WIN32) || defined (__WIN32__)
#define LL __int64
#define LLS "%" "I" "6" "4" "d"
#else
#define LL long long
#define LLS "%" "l" "l" "d"
#endif



int main(int argc, char** argv) {
    //read;
    int t,n,x,sum,cnt,now_sum;
    scanf("%d",&t);
    while(t--) {
        scanf("%d%d",&n,&x);
        sum = x;
        now_sum = 0;
        cnt = 1;
        for(int i=1; i<n; i++) {
            scanf("%d",&x);
            now_sum += x;
            if(now_sum > sum) {
                sum = sum + now_sum;
                now_sum = 0;
                cnt ++;
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值