码迷,mamicode.com
首页 > 其他好文 > 详细

J-max sum

时间:2016-08-08 12:29:11      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:

这个就是最大连续子序列之和,然后再输出第一个和最后一个,在输出的地方还是有点

#include <iostream>
using namespace std;

int main()
{
    int t,n,temp,pos1,pos2,max,now,x,i,j;
    cin>>t;
    for (i=1;i<=t;i++)
    {
        cin>>n>>temp;
        now=max=temp;
        pos1=pos2=x=1;
        for (j=2;j<=n;j++)
        {
            cin>>temp;
            if (now+temp<temp)
                now=temp,x=j;
            else
                now+=temp;
            if (now>max)
                max=now,pos1=x,pos2=j;
        }
        cout<<"Case "<<i<<":"<<endl<<max<<" "<<pos1<<" "<<pos2<<endl;
        if (i!=t)
            cout<<endl;
    }
    return 0;
}

  

懵逼

J-max sum

标签:

原文地址:http://www.cnblogs.com/yintoki/p/5748501.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!