hdu 1003 前缀和的应用

输出太恶心不解释......思路很简单

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#define MAX 100007

using namespace std;

int lef,rig;
int ans;
int sum,loc;

int main ( )
{
    int t,n,a;
    scanf ( "%d" , &t );
    int c = 1;
    while ( t-- )
    {
        int ans = -99999999;
        int minn = 99999999;
        sum = 0;
        scanf ( "%d" , &n );
        for ( int i = 1 ; i <= n ; i++ ) 
        {
            scanf ( "%d" , &a );
            sum += a;
            if ( minn >= 0 )
            {
                if ( sum > ans ) ans = sum , lef = 1 , rig = i;
            }
            else if ( sum - minn > ans )
                ans = sum -minn , lef = loc , rig = i;
            if ( sum < minn) minn = sum ,loc = i+1;
        }
        printf ( "Case %d:\n" , c++ );
        printf ( "%d %d %d\n" , ans , lef , rig );
        if(t)  puts ( "" );
    }
}


你可能感兴趣的:(C++,动态规划,前缀和)