Nyoj 983 首尾相连数组的最大子数组和
2014-05-13 14:58
369 查看
题目来源:http://acm.nyist.net/JudgeOnline/problem.php?pid=983
参考:/article/10999512.html
参考:/article/10999512.html
#include <iostream> #include <cstring> #include <cstdio> #include <climits> using namespace std; int main() { int iMax, iMax1, iMax2, sum, tmp, tmp1, iMin, a, n; while(~scanf("%d", &n)) { iMax1 = INT_MIN, iMin = INT_MAX, tmp = tmp1 = sum = 0; while(n--) { scanf("%d", &a); sum += a; tmp = tmp < 0 ? (tmp + a) : a;//最小连续子段和 tmp1 = tmp1 > 0 ? (tmp1 + a) : a;//最大连续子段和 if(tmp < iMin) iMin = tmp; if(tmp1 > iMax1) iMax1 = tmp1; } iMax2 = sum - iMin; iMax = max(iMax1, iMax2); if(iMax < 0) iMax = 0; printf("%d\n", iMax); } return 0; }
相关文章推荐
- html5 canvas绘图-刻度仪表盘的绘制
- 3. 枚举
- 十二.3 长颈鹿 保护
- 得之不易的180天:思科中国总部落户杭州始末
- 12 周 长颈鹿类对动物类的继承 private继承方式下
- 十二周——教师兼干部类
- Android 4.0 ProGuard 代码混淆
- Java配置环境变量
- 长颈鹿类对动物类的继承
- [转载]线程池ThreadPoolExecutor使用简介
- Android开发:setAlpha()方法和常用RGB颜色表----颜色, r g b分量数值(int), 16进制表示 一一对应
- 用Google Chart API展示简单的数据以及WordPress示例
- 位图思想
- 非接触式电子音乐控制器:CHIMAERA
- Socket学习笔记
- Windows下编译VLC
- boost asio allocation 例子
- arm9时钟及定时器
- 第十一周上机项目二拓展
- java 排列组合(递归实现)