zoukankan      html  css  js  c++  java
  • HDOJ_1003_MaxSum

    AC代码:

    #include <iostream>
    #include <cstdio>
    #define Max 100005
    using namespace std;
    int a[Max];
    int main(void)
    {
        freopen("in.txt","r",stdin);
        int T,count=0;
        long long n;
        scanf("%d",&T);
        while(T--)
        {
            int head=1,rear,curhead=1;
            long long sum=0,max=-2000;
            scanf("%lld",&n);
            for(int i=1;i<=n;i++)
            {
                scanf("%d",&a[i]);
                if(sum<0)
                {
                    sum=a[i];
                    curhead=i;
                }
                else
                {
                    sum+=a[i];
                }
                if(max<sum)
                {
                    head=curhead;
                    rear=i;
                    max=sum;
                }
            }
            count++;
            if(T!=0)
                printf("Case %d:
    %lld %d %d
    
    ",count,max,head,rear);
            else
                printf("Case %d:
    %lld %d %d
    ",count,max,head,rear);
        }
        
        
        
        
        
        fclose(stdin);
        return 0;
    }
  • 相关阅读:
    前端基础知识1
    mysql作业
    mysql了解知识点
    mysql3
    数据库作业2
    循环结构经典题型
    计算1
    猜数字游戏
    css的显示
    定位和position定位
  • 原文地址:https://www.cnblogs.com/phaLQ/p/10030022.html
Copyright © 2011-2022 走看看