`
endual
  • 浏览: 3545088 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

HDU ACM 1003

 
阅读更多

 

Max Sum

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 66796    Accepted Submission(s): 15297


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
 

Author
Ignatius.L

 

 

 

 

import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		int t, i;
		Scanner in = new Scanner(System.in);
		t = in.nextInt();
		for (i = 0; i < t; i++) {
			anster(in, i + 1);

			if (i != t - 1)
				System.out.println();
		}
	}

	private static void anster(Scanner in, int k) {

		int l = 0;
		int r = 0;
		int sum = 0;
		int count = in.nextInt();
		int num;
		int max = -1001; 
		int tempStep = 1;

		for (int i = 0; i < count; i++) {
			num = in.nextInt();
			sum = sum + num;

			if (sum > max) {
				l = tempStep;
				r = i + 1;
				max = sum;
			}

			if (sum < 0) {

				sum = 0;
				tempStep = i + 2;

			}
		}

		System.out.println("Case " + k + ":");
		System.out.println(max + " " + l + " " + r);
	}

}
 
分享到:
评论

相关推荐

    HDU_2010.rar_hdu 2010_hdu 20_hdu acm20

    【标题】"HDU_2010.rar"是一个压缩包文件,其中包含了与"HDU 2010"相关的资源,特别是针对"HDU ACM20"比赛的编程题目。"hdu 2010"和"hdu 20"可能是该比赛的不同简称或分类,而"hdu acm20"可能指的是该赛事的第20届...

    hdu acm 教案(7)

    HDU ACM教案是针对ACM/ICPC(国际大学生程序设计竞赛)的训练教程,旨在帮助参赛者提升算法和编程技能。"搜索入门"这部分内容是教程中的一个重要章节,主要介绍在解决算法问题时如何有效地运用搜索策略。在这个章节...

    hdu_ACM.rar_ACM_hdu_hdu acm_hdu_ACM_杭电ACM

    杭电hdu acm资料所用杭电的acm题

    (HDUACM201303版_07)背包专题

    杭电ACM课件2014版之 (HDUACM201303版_07)背包专题

    hdu acm 教案(3)

    HDU ACM教案是针对ACM/ICPC(国际大学生程序设计竞赛)的训练教程,旨在提升参赛者在算法和编程方面的能力。动态规划是计算机科学中一种强大的问题解决方法,尤其在处理最优化问题时非常有效。在这个教案中,我们将...

    (HDUACM2010版_13)二分匹配及其应用

    杭电ACM课件2014版之(HDUACM2010版_13)二分匹配及其应用

    (HDUACM2010版_08)母函数

    (HDUACM2010版_08)母函数(HDUACM2010版_08)母函数(HDUACM2010版_08)母函数(HDUACM2010版_08)母函数(HDUACM2010版_08)母函数(HDUACM2010版_08)母函数

    HDU_ACM培训课件(完整版)

    HDU_ACM培训课件是面向参与ACM(国际大学生程序设计竞赛,International Collegiate Programming Contest,简称ICPC)的学员准备的一套完整的教程资源。这个压缩包包含了丰富的学习资料,旨在帮助参赛者提升编程技能...

    hdu acm 2010多校联合(10)1009

    【标题】"hdu acm 2010多校联合(10)1009" 是2010年ACM/ICPC(国际大学生程序设计竞赛)多校联合比赛的第十场比赛中的一道题目,编号为1009。这道题目涉及到算法竞赛中的常见问题解决策略,通常在这样的比赛中,...

    HDUACM2010版_14)Hash及应用

    HDUACM2010版_14)Hash及应用HDUACM2010版_14)Hash及应用HDUACM2010版_14)Hash及应用HDUACM2010版_14)Hash及应用

    HDU acm-PPT课件

    【ACM入门与提高:HDU ACM竞赛课程详解】 ACM(国际大学生程序设计竞赛,International Collegiate Programming Contest,简称ICPC或ACM/ICPC)是一项全球性的竞赛,旨在激发大学生对计算机科学的兴趣,提升他们的...

    杭电HDU ACM培训课件

    《杭电HDU ACM培训课件》是一份珍贵的学习资源,源自杭州电子科技大学的ACM竞赛培训课程。这些课件是官方论坛上分享的,旨在为那些积分不足无法获取资源或者对ACM编程竞赛感兴趣的初学者提供帮助。下面将详细阐述这...

    hdu acm2000至2099参考源码

    HDU ACM(ACM/ICPC国际大学生程序设计竞赛)是一个知名的编程竞赛平台,它提供了大量的算法题目供参赛者挑战。这些题目旨在提升参赛者的算法设计、编程和问题解决能力。"hdu acm2000至2099参考源码"是针对这个平台上...

    HDU ACM 部分简单题 JAVA

    【标题】"HDU ACM 部分简单题 JAVA" 涉及的是在编程竞赛领域,特别是ACM(国际大学生程序设计竞赛)中的题目解决,使用的编程语言是JAVA。HDU(杭州电子科技大学)是知名的在线编程竞赛平台,提供各种难度等级的编程...

    (HDUACM201403版_04)递推求解

    杭电ACM课件2014版之 (HDUACM201403版_04)递推求解

    hangdianACM.rar_hangdiana_hdu acm_www.hangdianacm_杭电

    这个压缩文件包含的是作者个人提交并解决的ACM(国际大学生程序设计竞赛,International Collegiate Programming Contest)题目,这些题目来源于HDU的在线编程平台。 【描述】"杭电的一些acm题目,都是我自己一个一...

    (HDUACM201303版_01)初识ACM 高清PPT

    杭电的ACM课件2014版之(HDUACM201303版_01)初识ACM

    (HDUACM2010版_06)并查集(最小生成树)

    (HDUACM2010版_06)并查集(最小生成树(HDUACM2010版_06)并查集(最小生成树(HDUACM2010版_06)并查集(最小生成树(HDUACM2010版_06)并查集(最小生成树

Global site tag (gtag.js) - Google Analytics