杭电1003 MAX SUN
Output
5 6 -1 5 4 -7
7 0 6 -1 1 -6 7 -5
14 1 4
Case 2:
7 1 6
代码如下:
#include <iostream>
using namespace std;
int main()
{
int t;
cin>>t;
if(t>=0&&t<=20)
{
for(int i=1;i<=t;i++)
{
int first,second,temp=1;
int sum=0,max=-1001;
int n,x;
cin>>n;
for(int j=1;j<=n;j++)
{
cin>>x;
sum=sum+x;
if(max<sum)
{
max=sum;
first=temp;
second=j;
}
if(sum<0)
{
sum=0;
temp=j+1;
}
}
cout<<"Case "<<i<<":"<<endl;
cout<<max<<" "<<first<<" "<<second<<endl;
if(i<t)
cout<<endl;
}
}
return 0;
}
杭电1003 MAX SUN的更多相关文章
- 杭电1003 Max Sum 【连续子序列求最大和】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1003 题目意思: 即给出一串数据,求连续的子序列的最大和 解题思路: 因为我们很容易想到用一个max ...
- 杭电 1003 Max Sum (动态规划)
参考:https://www.cnblogs.com/yexiaozi/p/5749338.html #include <iostream> #include <cstdio> ...
- 杭电1003 Max Sum TLE
这一题目是要求连续子序列的最大和,所以在看到题目的一瞬间就想到的是把所有情况列举出来,再两个两个的比较,取最大的(即为更新最大值的意思),这样的思路很简单,但是会超时,时间复杂度为O(n^3),因为有 ...
- 杭电1003 最大子串(第二次AC) 当作DP的训练吧
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- 2018 Multi-University Training Contest 1 杭电多校第一场
抱着可能杭电的多校1比牛客的多校1更恐怖的想法 看到三道签到题 幸福的都快哭出来了好吗 1001 Maximum Multiple(hdoj 6298) 链接:http://acm.hdu.edu. ...
- 2017杭电ACM集训队单人排位赛 - 6
2017杭电ACM集训队单人排位赛 - 6 排名 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 59 1 X X 1 1 X X 0 1 ...
- 杭电acm 1002 大数模板(一)
从杭电第一题开始A,发现做到1002就不会了,经过几天时间终于A出来了,顺便整理了一下关于大数的东西 其实这是刘汝佳老师在<算法竞赛 经典入门 第二版> 中所讲的模板,代码原封不动写上的, ...
- 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”
按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...
随机推荐
- LeetCode Number of Digit One
原题链接在这里:https://leetcode.com/problems/number-of-digit-one/ 每10个数, 有一个个位是1, 每100个数, 有10个十位是1, 每1000个数 ...
- C语言:通过返回指针的形式找出数组的最大值和最小值
// // main.c // Pointer_max_min(return) // // Created by ma c on 15/8/2. // Copyright (c) 2015年 ...
- ELK-Python(一)
不具有通用性,留作纪念. [root@GXB-CTRLCENTER python]# cat insert_active_user.py #!/usr/bin/env python # -*- cod ...
- vs2010 问题 LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
vs2010 问题 LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏 在安装 VS2010 后,再安装 VS2012 VS2015 等,原来的 .N ...
- 框架基础——全面解析Java注解
为什么学习注解? 学习注解有什么好处? 学完能做什么? 答:1. 能够读懂别人写的代码,特别是框架相关的代码: 2. 让编程更加简洁,代码更加清晰: 3. 让别人高看一眼. spring.mybati ...
- shell中引用其他脚本的方法
在Shell中引用其他脚本的方法是source filename.sh 或 . filename.sh 注意: . 和 filename.sh之间必须有空格
- cacti批量添加主机脚本
#!/bin/bash ##cacti批量脚本位置 device=/var/www/html/cacti/cli/add_device.php graphs=/var/www/html/cacti/c ...
- stack note
参考 http://www.cnblogs.com/java06/archive/2012/10/16/3122428.html 1,顺序栈 定义栈: #define stacksize 1000; ...
- Effective C++ 6.继承与面向对象设计
//条款32:确定你的public继承塑模出is-a关系 // 1.public继承意味着is-a的关系,适用在基类上的方法都能用于派生类上. //条款33:避免遮掩继承而来的名称 // 1.在pub ...
- PostgreSQL Replication之第十章 配置Slony(6)
10.6 执行故障切换 一旦您学会了如何复制表并将它们添加到集合中,是时候学习故障转移了.基本上,我们可以在两个两种类型的故障转移之间做出区分: • 计划内故障转移 • 计划外故障转移和崩溃 在本节, ...