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. int a[3];中a+1与&amp;a+1差别 -- C

    int a[3]; a 和 &a 的地址一样的. a+1 == a + 1*sizeof(int);跳跃是一个数组元素大小 &a+1 == a + 3*sizeof(int);跳跃是整 ...

  2. BZOJ 1012 线段树||单调队列

    非常裸的线段树  || 单调队列: 假设一个节点在队列中既没有时间优势(早点入队)也没有值优势(值更大),那么显然不管在如何的情况下都不会被选为最大值. 既然它仅仅在末尾选.那么自然能够满足以上的条件 ...

  3. c多线程学习

    http://www.ibm.com/developerworks/cn/linux/thread/posix_thread1/index.html http://blog.chinaunix.net ...

  4. asp.net core mvc视频A:笔记2-4.ActionResult(动作结果,即返回值)

    json类型测试 方法一:实例化对象方式 代码 运行结果 方法二:封装方式 代码改动 运行结果 重点视图返回介绍,其他的不做介绍了 项目文件目录及文件添加 代码 运行结果 如果要显示的不是默认视图,可 ...

  5. Storm/Cassandra集成错误:NoSuchMethodError: concurrent.Futures.withFallback

    本文原文出处: http://blog.csdn.net/bluishglc/article/details/50443205 严禁不论什么形式的转载.否则将托付CSDN官方维护权益. 2015年的最 ...

  6. C++ 输出100—999中所有的水仙花数

    输出100-999中所有的水仙花数,若3位数xyz满足 , 则xyz为水仙花数,例如 , 因此153是水仙花数. #include <iostream> using namespace s ...

  7. Linux下画原理图和PCB

    Linux下画原理图和PCB Windows下大名鼎鼎的Allegro和经典的Protel 99SE都是不支持Linux操作系统的.做Linux驱动开发免不了要看一下原理图和PCB. 一般的做法有三种 ...

  8. python常见面试题(二)

    1. 到底什么是Python?你可以在回答中与其他技术进行对比(也鼓励这样做). 下面是一些关键点: Python是一种解释型语言.这就是说,与C语言和C的衍生语言不同,Python代码在运行之前不需 ...

  9. linux下tomcat6无法显示图片验证码 少了图形插件

    linux下tomcat6无法显示图片验证码(windows下显示正常) 原创 2015年10月20日 10:31:47 3526 linux下tomcat6无法显示图片验证码(windows下显示正 ...

  10. Crashing Robots - poj 2632

      Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8352   Accepted: 3613 Description In ...