CodeForces
来源:互联网 发布:java new string 编辑:程序博客网 时间:2024/06/14 10:39
题目大意:字符串是由0和1组成,求字符串的最长子串,使0和1的数目相同
记录0和1的个数,然后当两个个数相同的情况下,进行暴力,求最大值
ps:还要注意整个字符串为平衡串的情况
#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <string>#include <algorithm>#include <vector>#include <stack>#include <queue>#include <map>#include <set>using namespace std;typedef long long ll;map<int,int> mp;int main() { int n; char s[1000001]; int ans = 0; int x = 0; int y = 0; cin >> n; cin >> s; for(int i = 0;i < n;i++) { if(s[i] == '1') { x++; } else y++; if(mp.count(y-x)) { ans = max(ans, i-mp[y-x]); } else { mp[y-x] = i; } } if(x == y) { ans = n; } cout << ans << endl; return 0; }
阅读全文
0 0
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Java开发中的23种设计模式详解
- python3 查看Django版本
- Android Text的宽高
- java 操作HBase
- Sublime中设置Python编译器
- CodeForces
- HDU-2568How far away
- 16级 《Web前端设计》 总目录
- 阿里Java开发规范IDEA开发插件
- 数据结构上机测试2-1:单链表操作A
- Windows下安装tensorflow步骤--更ok
- LeetCode Blog for course "Algorithms" -- Problem 9
- 【C++】函数的传递方式
- selection does not contain a main type错误