http://www.geeksforgeeks.org/maximum-contiguous-circular-sum/

 #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
#include <map>
using namespace std; bool allneg(int arr[], int n) {
for (int i = ; i < n; i++) {
if (arr[i] > ) return false;
}
return true;
} int maxsum(int arr[], int n) {
int tmp = ;
int ans = INT_MIN;
for (int i = ; i < n; i++) {
tmp += arr[i];
ans = max(ans, tmp);
tmp = max(tmp, );
}
return ans;
} int maxcircular(int arr[], int n) {
int ans = maxsum(arr, n);
if (allneg(arr, n)) return ans;
int sum = ;
for (int i = ; i < n; i++) {
sum += arr[i];
arr[i] = -arr[i];
}
return max(ans, sum + maxsum(arr, n));
} int main() {
int arr[] = {, , -, , -, -, , -, };
cout << maxcircular(arr, ) << endl;
return ;
}

Data Structure Array: Maximum circular subarray sum的更多相关文章

  1. Data Structure Array: Maximum sum such that no two elements are adjacent

    http://www.geeksforgeeks.org/maximum-sum-such-that-no-two-elements-are-adjacent/ #include <iostre ...

  2. Data Structure Array: Maximum of all subarrays of size k

    http://www.geeksforgeeks.org/maximum-of-all-subarrays-of-size-k/ #include <iostream> #include ...

  3. Subarray Sum & Maximum Size Subarray Sum Equals K

    Subarray Sum Given an integer array, find a subarray where the sum of numbers is zero. Your code sho ...

  4. Subarray Sum & Maximum Size Subarray Sum Equals K && Subarray Sum Equals K

    Subarray Sum Given an integer array, find a subarray where the sum of numbers is zero. Your code sho ...

  5. leetcode 560. Subarray Sum Equals K 、523. Continuous Subarray Sum、 325.Maximum Size Subarray Sum Equals k(lintcode 911)

    整体上3个题都是求subarray,都是同一个思想,通过累加,然后判断和目标k值之间的关系,然后查看之前子数组的累加和. map的存储:560题是存储的当前的累加和与个数 561题是存储的当前累加和的 ...

  6. [LeetCode] Maximum Size Subarray Sum Equals k 最大子数组之和为k

    Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If t ...

  7. Maximum Size Subarray Sum Equals k LT325

    Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If t ...

  8. [LeetCode] 325. Maximum Size Subarray Sum Equals k 和等于k的最长子数组

    Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If t ...

  9. Data Structure Array: Find if there is a subarray with 0 sum

    http://www.geeksforgeeks.org/find-if-there-is-a-subarray-with-0-sum/ #include <iostream> #incl ...

随机推荐

  1. eclipse上的git命令使用浅析,搭建Maven项目

    eclipse上的git命令使用浅析 2016-03-31 14:44   关于eclipse上git的安装和建立代码仓库的文章比较多,但作为一个初识git的人更希望了解每个命令的作用. 当项目连接到 ...

  2. 利用CFAbsoluteTimeGetCurrent()计算时间差

    开发中,遇到计算时间差的问题,利用CFAbsoluteTimeGetCurrent()可以很方便的进行计算 实例: 场景:类似购物车中修改商品数量的功能,如下图所示,要求,修改完的数量,要同步到服务器 ...

  3. 【C语言疯狂讲义】(三)C语言运算符

    1.运算符: 连接两个操作数(常量.变量)的符号 用运算符依照一定的规则连接的式子称为表达式 运算符的分类: 1)操作数的个数: 单目运算(++     sizeof    !) 双目运算符:... ...

  4. nginx proxy cache配置和清理

    1.nginx需要编译Purge模块 2.nginx.conf 配置cache: proxy_cache_path  /home/cache/xxx levels=1:2  keys_zone=cac ...

  5. WAS集群系列(3):集群搭建:步骤1:准备文件

    说明:"指示轨迹"为"点选顺序",截图为点击后效果截图 环境 项目点 指标 WAS版本号 7.0 操作系统 Windows 2008 系统位数 64bit 内存 ...

  6. uboot和内核分区的改动

    随着内核的更新,内核越来越大,uboot给nand的kernel分区默认是2M的 device nand0 <nandflash0>, # parts = 4  #: name       ...

  7. warning: push.default is unset; its implicit value is changing in Git 2.0 from 'matching' to 'simple'.

    'matching'参数是 git 1.x 的默认行为,其意是如果你执行 git push 但没有指定分支,它将 push 所有你本地的分支到远程仓库中对应匹配的分支. 而 Git 2.x 默认的是 ...

  8. Mina代码跟踪(1)

    1  NioSocketAcceptor类关系图 1.1 NioSocketAcceptor acceptor = new NioSocketAcceptor(5); NioSocketAccepto ...

  9. winerror.h中的内容(可以查看last error对应)

    /************************************************************************* ** winerror.h -- error co ...

  10. Linux守护进程简单介绍和实例具体解释

    Linux守护进程简单介绍和实例具体解释 简单介绍 守护进程(Daemon)是执行在后台的一种特殊进程.它独立于控制终端而且周期性地执行某种任务或等待处理某些发生的事件.守护进程是一种非常实用的进程. ...