http://www.geeksforgeeks.org/largest-subarray-with-equal-number-of-0s-and-1s/

 #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
#include <map>
using namespace std; void findsubarray(int arr[], int n) {
map<int, vector<int> > S;
int sum = ;
for (int i = ; i < n; i++) {
sum += (arr[i] == ? - : );
if (S.find(sum) != S.end()) S[sum].push_back(i);
else S[sum] = vector<int>(, i);
}
int ans = ;
for (map<int, vector<int> >::iterator it = S.begin(); it != S.end(); it++) {
if ((it->first) == ) ans = max(ans, (it->second)[(it->second).size()-]+);
else ans = max(ans, (it->second)[(it->second).size()-] - (it->second)[]);
}
cout << ans << endl;
} int main() {
int arr[] = {, , , , , , };
findsubarray(arr, );
return ;
}

Data Structure Array: Largest subarray with equal number of 0s and 1s的更多相关文章

  1. Data Structure Array: Find the Missing Number

    http://www.geeksforgeeks.org/find-the-missing-number/ 1. use sum formula, O(n), O(1) 2. use XOR, O(n ...

  2. 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 ...

  3. Data Structure Array: Given an array of of size n and a number k, find all elements that appear more than n/k times

    http://www.geeksforgeeks.org/given-an-array-of-of-size-n-finds-all-the-elements-that-appear-more-tha ...

  4. Data Structure Array: Maximum circular subarray sum

    http://www.geeksforgeeks.org/maximum-contiguous-circular-sum/ #include <iostream> #include < ...

  5. Data Structure Array: Move all zeroes to end of array

    http://www.geeksforgeeks.org/move-zeroes-end-array/ #include <iostream> #include <vector> ...

  6. Data Structure Array: Sort elements by frequency

    http://www.geeksforgeeks.org/sort-elements-by-frequency-set-2/ #include <iostream> #include &l ...

  7. Data Structure Array: Find the two numbers with odd occurrences in an unsorted array

    http://www.geeksforgeeks.org/find-the-two-numbers-with-odd-occurences-in-an-unsorted-array/ #include ...

  8. Data Structure Array: Longest Monotonically Increasing Subsequence Size

    http://www.geeksforgeeks.org/longest-monotonically-increasing-subsequence-size-n-log-n/ #include < ...

  9. Data Structure Array: Find the minimum distance between two numbers

    http://www.geeksforgeeks.org/find-the-minimum-distance-between-two-numbers/ #include <iostream> ...

随机推荐

  1. python--pipe

    1.pipe 除了使用队列外,还可以使用管道在进程间执行消息传递 pipe([]duplex) 在进程间创建一条管道,并返回元组(conn1,conn2),其中conn1和conn2是表示管道两端的C ...

  2. Python之比较运算符

    python中的比较运算符有8个. 运算 | 含义=============< | 小于<= | 小于等于> | 大于>= |大于等于== | 等于!= |不等于is | 是i ...

  3. URL重写:Rewirte模块原理详解

    Apache+PHP+MySQL Rewirte主要的功能就是实现URL的跳转和隐藏真实地址,基于Perl语言的正则表达式规范.平时帮助我们实现拟静态,拟目录,域名跳转,防止盗链等.本文将针对mod_ ...

  4. Redis学习笔记-Redis内部数据结构

    Redis内部数据结构 Redis和其他key-value数据库的很大区别是它支持非字符串类型的value值.它支持的value值的类型如下: sds (simple dynamic string) ...

  5. VS2012删除选项卡菜单中的"关闭所有文档"

    delete the "close all documents" item of tab menu in vs2012 Tools -> Customize -> Co ...

  6. 自己定义popupwindow二三事

    效果图: 代码: public class ViewActivity extends Activity implements View.OnClickListener { PopupWindow po ...

  7. PyCharm搭建Spark开发环境 + 第一个pyspark程序

    一, PyCharm搭建Spark开发环境 Windows7, Java 1.8.0_74, Scala 2.12.6, Spark 2.2.1, Hadoop 2.7.6 通常情况下,Spark开发 ...

  8. 【数据挖掘】分类之kNN(转载)

    [数据挖掘]分类之kNN 1.算法简介 kNN的思想很简单:计算待分类的数据点与训练集所有样本点,取距离最近的k个样本:统计这k个样本的类别数量:根据多数表决方案,取数量最多的那一类作为待测样本的类别 ...

  9. ICloneable接口 Clone 深拷贝 浅拷贝

    需要字段本身也实现了深拷贝Clone.应用场景不多,意义不大. 1. 隐含式地要求其子类和引用类也要实现ICloneable接口,如果引用层次比较深类似一个网状或树形接口,增加复杂性. 2. 考虑给s ...

  10. wireshark:Couldn't run /usr/bin/dumpcap in child process: Permission denied

    When start wireshark, I met an error like: 引用 Couldn't run /usr/bin/dumpcap in child process: Permis ...