uva-507

  题意:连续序列和最大,直接枚举。。。。。

代码跑了2.4s.QAQ

 
#include <string>
#include<iostream>
#include<map>
#include<memory.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<math.h>
#include<iomanip>
#include<bitset>
#include"math.h"
namespace cc
{
    using std::cout;
    using std::endl;
    using std::cin;
    using std::map;
    using std::vector;
    using std::string;
    using std::sort;
    using std::priority_queue;
    using std::greater;
    using std::vector;
    using std::swap;
    using std::stack;
    using std::queue;
    using std::bitset;



    constexpr int N = 20001;
    int seg[N] = { 0 };
    void solve()
    {
        int n;
        cin >> n;
        int t;
        int cases = 1;
        while (n--) 
        {
            cin >> t;
            --t;
            for (int i=0;i<t;i++) 
                cin >> seg[i];
            int as=-1, ae=-1;
            int amax = -1;
            for (int s=0;s<t;s++) 
            {
                int curMax = 0;
                for (int e=s;e < t;e++) 
                {
                    curMax += seg[e];
                    if (curMax > amax)
                    {
                        amax = curMax;
                        as = s+1;
                        ae = e+2;
                    }
                    else if (curMax == amax&& as!=-1)
                    {
                        if (ae - as-1 < e - s)
                        {
                            as = s+1;
                            ae = e+2;
                        }
                    }
                }
                

            }
            if (as==-1) 
            {
                
                cout << "Route "<<cases<<" has no nice parts" << endl;
            }
            else
            {
                cout<<"The nicest part of route "<<cases <<" is between stops "<<as<<" and "<<ae<<endl;
            }
            cases++;
            

        }
          
    }
};


int main()
{

#ifndef ONLINE_JUDGE
    freopen("d://1.text", "r", stdin);
#endif // !ONLINE_JUDGE
    cc::solve();

    return 0;
}

 

上一篇:列表解析


下一篇:操作列表的大致说明