• HDU 1003 Max Sum


    Problem Description
    Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.
     
    Input
    The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).
     
    Output
    For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.
     
    Sample Input
    2
    5 6 -1 5 4 -7
    7 0 6 -1 1 -6 7 -5
     
    Sample Output
    Case 1:
    14 1 4
    Case 2:
    7 1 6
    这个题就是求最大联系和,我靠,我竟然在这种题上WA了啊,后来又PE了,人生啊!!!!转战HDU的第一题,难道是HDU想给我一个下马威
    #include<map>
    #include<set>
    #include<queue>
    #include<cmath>
    #include<vector>
    #include<cstdio>
    #include<string>
    #include<cstring>
    #include<cstdlib>
    #include<iostream>
    #include<algorithm>
    #define  inf 0x0f0f0f0f
    
    using namespace std;
    
    const double pi=acos(-1.0);
    const double eps=1e-8;
    typedef pair<int,int>pii;
    
    int a[100001];
    int x,y,maxtemp,maxsum,tempx;
    
    void get_max(int n)
    {
        x=1;y=1,tempx=1;
        maxtemp=maxsum=a[1];
        for (int i=2;i<=n;i++)
        {
            if (maxtemp<0) {maxtemp=a[i];tempx=i;}
            else maxtemp+=a[i];
            if (maxsum<maxtemp)
            {
                maxsum=maxtemp;
                x=tempx;
                y=i;
            }
        }
        return;
    }
    
    int main()
    {
       // freopen("in.txt","r",stdin);
    
        int t,n;
        scanf("%d",&t);
        for (int k=1;k<=t;k++)
        {
            scanf("%d",&n);
            for (int i=1;i<=n;i++) scanf("%d",&a[i]);
            get_max(n);
            printf("Case %d:
    ",k);
            printf("%d %d %d
    ",maxsum,x,y);
            if (k!=t) printf("
    ");
        }
        //fclose(stdin);
        return 0;
    }
    至少做到我努力了
  • 相关阅读:
    SAP的PI日志查看工具
    微信小程序调用SAP发布的REST显示数据列表
    SAP发布REST/HTTP接口
    SAP的JSON没有双引号问题
    SAP扩展库位
    函数使用十一:BAPI_BANK_CREATE
    竟然有人在群里谈交钱培训PI。。。。等哥哥有时间,断了你们的财路
    FPM十一:点击POPUP显示明细
    WDA基础十八:Select option配置
    SAP常见查询组合
  • 原文地址:https://www.cnblogs.com/chensunrise/p/3685563.html
Copyright © 2020-2023  润新知