最大连续和 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~~~但是他太弱逼了,有些地方完全靠运气:(我们来简化一下 ...
随机推荐
- shell练习--PAT题目1005:继续(3n+1)猜想(全绿失败喜加一)
卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况稍微有些复杂. 当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数.例如对 n=3 进行验证的时 ...
- linux 系统时间 硬件时间
Linux时钟分为系统时钟(System Clock)和硬件时钟(Real Time Clock,简称RTC).系统时钟是指当前Linux Kernel中的时钟:而硬件时钟则是主板上由电池供电的时钟, ...
- 杨辉三角 x
杨辉三角是美丽的数学结晶,其结论往往多蕴含自然之美. ——以下内容均摘抄自题解. 例题: 洛谷P1762 偶数 正如这题所示,数据在n<=10^15的范围内则引导我们去寻找空间更节省,速率更高 ...
- Oracle-RAC sysdate和current_date时间不一致,导致客户端连接时间延迟
[oracle@oracle-db1 ~]$ dateTue Oct 10 14:20:56 CST 2017[oracle@oracle-db1 ~]$ cat /etc/sysconfig/clo ...
- Django基础之二(URL路由)
URL路由 简介 对于高质量的web应用来说,使用简洁,优雅的URL路由是一个值得尊重的细节,Django可以随心所欲的设计URL,不受框架的约束 为了给一个应用设计URL,你需要一个Python模块 ...
- kubernetes master 更换ip(单节点)
问题分析 master ip地址变更以后,我们首先应该检查以下内容: /etc/kubernetes/manifests下面的config配置文件,替换里面对应的ip 相关的证书文件 客户端文件 解决 ...
- 配置OpenLDAP,Java操作LDAP,DBC-LDAP进访问
LDAP快速入门 1. LDAP简介 LDAP(轻量级目录访问协议,Lightweight Directory Access Protocol)是实现提供被称为目录服务的信息服务.目录服务是一种特殊的 ...
- leetcode-mid-design-380. Insert Delete GetRandom O(1)
mycode import random class RandomizedSet(object): def __init__(self): """ Initialize ...
- maven 成长之路
1配置maven 环境变量 新建系统变量 M2_HOME :E:\apache-maven-3.5.2 在系统变量 path中添加 E:\apache-maven-3.5.2\bin 运行 mvn - ...
- 从 sourcemap 中获取源码
使用 paazmaya/shuji: Reverse engineering JavaScript and CSS sources from sourcemaps 可以从 sourcemap 中获取源 ...