https://vjudge.net/problem/HDU-1003

注意考虑如果全为负的情况,特判。

还有输出格式,最后一个输出不用再空行。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define INF 1e9
typedef long long ll;
using namespace std;
int n, m, a[];
int main()
{
IO;
cin >> n;
int kase=;
while(n--){
cin >> m;
for(int i = ; i < m; i++){
cin >> a[i];
}
int sum = , maxm = -INF;
int from = ;
int ans1 = , ans2 = -;
for(int i = ; i < m; i++){
sum += a[i];
if(sum < ){
sum = ;
from = i+;
}
else{
if(sum > maxm){
maxm = sum;
ans1 = from;
ans2 = i;
}
}
}
cout << "Case " << ++kase << ":" << endl;
if(ans2 == -){//sum一直小于零,每位<0
maxm = -INF;
for(int i = ; i < m; i++){
if(a[i] > maxm){
maxm = a[i];
ans1 = i; ans2 = i;
}
}
cout << maxm << " " << ans1+ << " " << ans2+ << endl;
}
else
cout << maxm << " " << ans1+ << " " << ans2+ << endl;
if(n != ) cout << endl;
}
return ;
}

hdu1003 Max Sum(最大子串)的更多相关文章

  1. 解题报告:hdu1003 Max Sum - 最大连续区间和 - 计算开头和结尾

    2017-09-06 21:32:22 writer:pprp 可以作为一个模板 /* @theme: hdu1003 Max Sum @writer:pprp @end:21:26 @declare ...

  2. [ACM_动态规划] hdu1003 Max Sum [最大连续子串和]

    Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum ...

  3. 杭电60题--part 1 HDU1003 Max Sum(DP 动态规划)

    最近想学DP,锻炼思维,记录一下自己踩到的坑,来写一波详细的结题报告,持续更新. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 Problem ...

  4. HDU1003 Max Sum(求最大字段和)

    事实上这连续发表的三篇是一模一样的思路,我就厚颜无耻的再发一篇吧! 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003 -------------- ...

  5. hdu1003 Max Sum(经典dp )

      A - 最大子段和 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Descr ...

  6. 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 ...

  7. HDU-1003 Max Sum(动态规划,最长字段和问题)

    Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  8. ACM学习历程—HDU1003 Max Sum(dp && 最大子序列和)

    Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub ...

  9. hdu1003 Max Sum【最大连续子序列之和】

    题目链接:https://vjudge.net/problem/HDU-1003 题目大意:给出一段序列,求出最大连续子序列之和,以及给出这段子序列的起点和终点. 解题思路:最长连续子序列之和问题其实 ...

随机推荐

  1. 3.ELK 之elasticsearch CRUD

    名词介绍 index: type: document: 数据类型: 索引(index)创建示例 .   type的创建(7.x之后)将会去掉该内容,点我看为什么? 参考脚本: mapping使用 其他 ...

  2. lr场景异常Continuing after Error -26479: Conversion of form submission data to the target charset failed: U_TRUNCATED_CHAR_FOUND解决方法

    在lr压测场景中执行,发现 一个事务都没有成功,很是奇怪,发现用linux的agent各种问题 查看lr运行日志 看到这里基本确定是编码的问题,然后想起lr设置编码的地方就那么几个,所以逐个尝试 改完 ...

  3. HDU4858 项目管理 其他

    原文链接https://www.cnblogs.com/zhouzhendong/p/HDU4858.html 题目传送门 - HDU4858 题意 给定一个无向图 $n$ .有 $m$ 条边. 每一 ...

  4. mysql解决数据库死锁问题

    为了保证数据的正确性,对数据库进行操作的时候都会进行上锁,也就是进行修改数据的时候同一时间只能有一个进程,当这个进程处理完了,释放锁了,其他进程才可以进行操作! 总是会碰见一些意外情况,导致数据库死锁 ...

  5. 063 SparkStream数据接收方式

    1.两种方式 2.Basic Source 由StreamingContext可以提供的API 上面做的wordcount中的方式就算是第一种方式. 3.Advanced Source 使用数据接收器 ...

  6. web发展阶段简介

     web1.0.web2.0和web3.0的区别前言: 其实并没有什么所谓的2.0.3.0,因为你没法准确的界定它是什么样的应用,也没法界定它是什么时候开始的,什么时候结束,它只是互联网本身发展的一种 ...

  7. oracle的存储过程和定时任务编写体会

    create or replace procedure clear_product is p_sql char(200) p_r_sql char(200) begin p_sql := ''; p_ ...

  8. thinkphp5控制器

    // 定义应用目录 define('APP_PATH', __DIR__ . '/../app/'); // 定义配置文件目录和应用目录同级 define('CONF_PATH', __DIR__.' ...

  9. Spark-Unit1-spark概述与安装部署

    一.Spark概述 spark官网:spark.apache.org Spark是用的大规模数据处理的统一计算引擎,它是为大数据处理而设计的快速通用的计算引擎.spark诞生于加油大学伯克利分校AMP ...

  10. 016.OpenStack及云计算(面试)常见问题

    什么是云计算? 云计算是一种采用按量付费的模式,基于虚拟化技术,将相应计算资源(如网络.存储等)池化后,提供便捷的.高可用的.高扩展性的.按需的服务(如计算.存储.应用程序和其他 IT 资源).   ...