最大连续和 Easy
InputThe 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).
OutputFor 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
#include<iostream>
#include<cstring>
#include<cstdio> using namespace std; void Solve(){
int n, x, st, h = , t = , tmp, ans = ;
static int Case = ;
scanf("%d", &n);
for(int i = ; i <= n; i++){
scanf("%d", &x);
if(i == ){
st = t = ;
tmp = ans = x;
}else{
if(x > tmp + x){
st = i;
tmp = x;
}else tmp += x;
}
if(tmp > ans){
h = st, t = i;
ans = tmp;
}
}
printf("Case %d:\n%d %d %d\n", ++Case, ans, h, t);
}
int main(){
int T;
scanf("%d", &T);
while(T--){
Solve();
if(T) printf("\n");
}
}
最大连续和 Easy的更多相关文章
- leetcode485——最大连续1的个数(easy)
一.题目描述 给定一个二进制数组, 计算其中最大连续1的个数. 示例 1: 输入: [1,1,0,1,1,1] 输出: 3 解释: 开头的两位和最后的三位都是连续1,所以最大连续1的个数是 3. 注意 ...
- ZOJ3802 Easy 2048 Again (状压DP)
ZOJ Monthly, August 2014 E题 ZOJ月赛 2014年8月 E题 http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...
- 【BZOJ3450】Tyvj1952 Easy 期望DP
[BZOJ3450]Tyvj1952 Easy Description 某一天WJMZBMR在打osu~~~但是他太弱逼了,有些地方完全靠运气:(我们来简化一下这个游戏的规则有n次点击要做,成功了就是 ...
- 【tyvj1952】easy
AK大神又AK了!!! orzorzorz 题意: 给出一个字符串由'x'.'o'.'?' '?'有一半的几率为'x' 一半几率为'o' 得分为所有连续的'o'的个数的平方和 如ooxooo 得分为2 ...
- Bzoj 3450: Tyvj1952 Easy 期望/概率,动态规划
3450: Tyvj1952 Easy Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 431 Solved: 325[Submit][Status] ...
- tyvj P1952 Easy(递推+期望)
P1952 Easy 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 某一天WJMZBMR在打osu~~~但是他太弱逼了,有些地方完全靠运气:(我们来简化一下 ...
- ACM-DP最大连续子——hdu1231
***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...
- 3450: Tyvj1952 Easy
3450: Tyvj1952 Easy Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 269 Solved: 198[Submit][Status] ...
- [Tyvj 1952] Easy
P1952 Easy 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 某一天WJMZBMR在打osu~~~但是他太弱逼了,有些地方完全靠运气:(我们来简化一下 ...
随机推荐
- 原生js数组排序(封装方法)
//两值互换 function Sort(arr, index){ //参数arr代表数组,index代表数组元素下标 arr[index] += arr[index + 1]; //a+=b; a ...
- linux-包管理器-4
安装 升级 查询 导入公钥 rpm -K|checksig rpmfile 检查包的完整性和签名 rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 ...
- 启动 jvm 参数小总结
1.启动某项目 nohup java -jar -Xms256m -Xmx512m -Dspring.config.location=/config/application.yml -Dfile.en ...
- 选择vim编辑器的7个理由
当我刚刚开始用 vi 文本编辑器的时候,我讨厌它!我认为这是有史以来设计上最痛苦和反人类的编辑器.但我还是决定我必须学会它,因为如果你使用的是 Unix,vi 无处不在并且是唯一一个保证你可以使用的编 ...
- MongoDB接口类函数
[接口类定义] [java] view plaincopy /** * 项目名:SpiderCrawler * 文件名:MongoDBDao.java * 描述:TODO(用一句话描述该文件做什么) ...
- 不属于java语言鲁棒性特点的是
A:java能检查程序在编译和运行时的错误 B:java能运行虚拟机实现跨平台 C:java自己操纵内存减少了内存出错的可能性 D:java还实现了真数组,避免了覆盖数据的可能 鲁棒性(Robus ...
- phpstorm的下载激活及定制使用和设置
1.下载地址: 链接:https://pan.baidu.com/s/19PbZnzq0x7grgBge-iHI3w&shfl=sharepset 提取码:dnte 2.激活码获取:http ...
- MyBatis框架之mybatis逆向工程自动生成代码
http://www.jb51.net/article/82062.htm Mybatis属于半自动ORM,在使用这个框架中,工作量最大的就是书写Mapping的映射文件,由于手动书写很容易出错,我们 ...
- Python 基础知识总结
strptime() 根据指定的格式将一个时间字符串解析为一个时间元组. time.strptime(time_str[,format]) 返回strcut_time对象 #time_str 是时间字 ...
- 在windows下使用Mingw搭建模拟Linux
1.到官网下载最新版Mingw 2.点击安装,最好选择默认路径,如果不是的话,路径中一定不能有空格. 3.选择安装,mingw-developer-toolkit.mingw32-base.mingw ...