【PAT甲级】1007 Maximum Subsequence Sum (25 分)
题意:
给出一个整数K(K<=10000),输入K个整数。输出最大区间和,空格,区间起点的数值,空格,区间终点的数值。如果有相同的最大区间和,输出靠前的。如果K个数全部为负,最大区间和输出0,区间起点的数值为a[1],区间终点的数值为a[n]。
AAAAAccepted code:
#include<bits/stdc++.h>
using namespace std;
int a[];
int main(){
int n;
cin>>n;
int mx=-1e9,ans=-1e9;
int startt=,endd=;
int tmp=;
for(int i=;i<=n;++i){
cin>>a[i];
if(mx<){
mx=a[i];
tmp=a[i];
}
else
mx+=a[i];
if(mx>ans){
startt=tmp;
endd=a[i];
ans=mx;
}
}
if(ans<)
cout<<"0 "<<a[]<<" "<<a[n];
else
cout<<ans<<" "<<startt<<" "<<endd;
return ;
}
【PAT甲级】1007 Maximum Subsequence Sum (25 分)的更多相关文章
- PAT 甲级 1007 Maximum Subsequence Sum (25)(25 分)(0不是负数,水题)
1007 Maximum Subsequence Sum (25)(25 分) Given a sequence of K integers { N~1~, N~2~, ..., N~K~ }. A ...
- PAT Advanced 1007 Maximum Subsequence Sum (25 分)
Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to ...
- PAT 甲级 1007. Maximum Subsequence Sum (25) 【最大子串和】
题目链接 https://www.patest.cn/contests/pat-a-practise/1007 思路 最大子列和 就是 一直往后加 如果 sum < 0 就重置为 0 然后每次 ...
- 1007 Maximum Subsequence Sum (25分) 求最大连续区间和
1007 Maximum Subsequence Sum (25分) Given a sequence of K integers { N1, N2, ..., NK }. A ...
- 1007 Maximum Subsequence Sum (25 分)
1007 Maximum Subsequence Sum (25 分) Given a sequence of K integers { N1, N2, ..., NK }. A ...
- PAT甲 1007. Maximum Subsequence Sum (25) 2016-09-09 22:56 41人阅读 评论(0) 收藏
1007. Maximum Subsequence Sum (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...
- PAT 1007 Maximum Subsequence Sum (25分)
题目 Given a sequence of K integers { N1 , N2 , ..., NK }. A continuous subsequence is define ...
- PAT 甲级 1007 Maximum Subsequence Sum
https://pintia.cn/problem-sets/994805342720868352/problems/994805514284679168 Given a sequence of K ...
- 数据结构课后练习题(练习一)1007 Maximum Subsequence Sum (25 分)
Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to ...
随机推荐
- ci/cd部署时遇到的一个问题
今天在部署项目的时候报了一个错Error response from daemon: endpoint with name xxx already exists in networ ...
- JavaScript 实现单例模式的两种方式
单例模式: 要求一个类只有一个实例化对象存在 这个实例化对象必须提供一个全局对外访问方式 这个实例化对象应当是私有的,不能被外界直接访问或者更改 方式1 get实现 唯一实例化:判断这个对象是否存在, ...
- MAC Address-Table Move Update Feature
MAC Address-Table Move Update The MAC address-table move update feature allows the switch to provide ...
- ubuntu 命令记录
1.su root 进入root模式 2.ifconfig 查看ip地址 3.ls 查看文件 4./etc/init.d/matrix-gui-2.0 stop 关闭matrix界面 5.cd /文 ...
- Nmap工具用法详解
Nmap Network Mapper 是一款开放源代码的网络探测和安全审核工具 1.介绍
- io异常
针对异常,JVM默认的处理方案: 一旦遇到程序出现了问题,就会把问题的类名,错误原因,错误的位置等信息打印在控制台,以便我们观察. 并且,会自动从当前出问题的地方停止掉.这种处理方案虽然可以,但是不够 ...
- 吴裕雄--天生自然Numpy库学习笔记:NumPy 矩阵库(Matrix)
import numpy.matlib import numpy as np print (np.matlib.empty((2,2))) # 填充为随机数据 numpy.matlib.zeros() ...
- StringUtils中isEmpty方法和isBlank方法的区别
1.StringUtils.isEmpty没有忽略空格参数,是以是否为空和是否存在为判断依据. 示例: StringUtils.isEmpty("yyy") = false Str ...
- JavaScript动画相关
JS动画原理 通过CSS缓慢变化从而实现动画效果 获取css属性 Window.getComputedStyle()方法返回一个对象,该对象在应用活动样式表并解析这些值可能包含的任何基本计算后报告元素 ...
- A10131013 Battle Over Cities (25分)
一.技术总结 这一题是考查图的知识,题目的意思要理解清楚,就是考查统计图中连通块的数量,也就是没有一个结点后. 怎么删除该结点,并且统计连通块的数量成为问题解决的关键,这里可以当访问到结点时,直接返回 ...