CF873B Balanced Substring
1到n内0,1个数相同的个数的最长字串
\(i>=j\)
\]
\]
这里把\((j-1)\)替换为\(j\)
\]
\]
枚举i,然后求前面和\(2*sum[i]-i\)相同的最小标号
这里可能有负数,所以map就好了
当然,因为\(2*sum[i]-i\)的值是在区间[-n,n]的
所以你可以直接+n用数组桶一下
不告诉你我写过线段树
#include <bits/stdc++.h>
#define ls rt<<1
#define rs rt<<1|1
#define FOR(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
const int maxn=1e5+7;
const int inf=0x3f3f3f3f;
int n,a[maxn],sum[maxn];
//map<int,int> mi;
int mi[maxn*2];
int main()
{
scanf("%d",&n);
FOR(i,1,n) scanf("%1d",&a[i]),sum[i]=sum[i-1]+a[i];
int ans=0;
memset(mi,inf,sizeof(mi));
mi[n]=0;
FOR(i,1,n) {
int tmp=n+2*sum[i]-i;
int zz=mi[tmp];
// if(!zz&&tmp!=0) zz=inf,mi[tmp]=inf;
ans=max(i-zz,ans);
mi[tmp]=min(zz,i);
}
cout<<ans;
return 0;
}
CF873B Balanced Substring的更多相关文章
- CF873B Balanced Substring (前缀和)
CF873B Balanced Substring (前缀和) 蛮有意思的一道题,不过还是.....................因为CF评测坏了,没有试过是否可过. 显然求\(\sum[i][0] ...
- [Codeforces 873B]Balanced Substring
Description You are given a string s consisting only of characters 0 and 1. A substring [l, r] of s ...
- 837B. Balanced Substring
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- CodeForces - 873B Balanced Substring(思维)
inputstandard input outputstandard output You are given a string s consisting only of characters 0 a ...
- Codeforces 873 B. Balanced Substring(前缀和 思维)
题目链接: Balanced Substring 题意: 求一个只有1和0的字符串中1与0个数相同的子串的最大长度. 题解: 我的解法是设1的权值是1,设0的权值是-1,求整个字符串的前缀和并记录每个 ...
- Balanced Substring
You are given a string s consisting only of characters 0 and 1. A substring [l, r] of s is a string ...
- 【Cf edu 30 B. Balanced Substring】
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- codefroces 873 B. Balanced Substring && X73(前缀和思想)
B. Balanced Substring You are given a string s consisting only of characters 0 and 1. A substring [l ...
- Codeforces 873B - Balanced Substring(思维)
题目链接:http://codeforces.com/problemset/problem/873/B 题目大意:一个字符串全部由‘0’和‘1’组成,当一段区间[l,r]内的‘0’和‘1’个数相等,则 ...
随机推荐
- CH0102 64位整数乘法 数论
正解:数论/一个神仙想法 解题报告: 先放传送门qwq 两种方法,都还挺妙的就都写了qwq 第一种是快速幂 把b用二进制表示成,ck*2k+ck-1*2k-1+...+c0*20 然后就可以表示成,a ...
- KVM VCPU线程调度问题的讨论
2017-11-15 今天闲着没有突然想了想VCPU线程调度的问题,具体描述如下: 当代表VCPU的线程获得控制权后,首先会通过KVM接口进入到内核,从内核进入到非根模式,那么此时站在全局调度器的点上 ...
- UIStoryboard跳转界面
/**1.创建Storyboard,加载Storyboard的名字,这里是自己创建的Storyboard的名字*/ UIStoryboard *storyboard = [UIStoryboard s ...
- python接口自动化-参数化
原文地址https://www.cnblogs.com/yoyoketang/p/6891710.html python接口自动化 -参数关联(一)https://www.cnblogs.com/11 ...
- testng入门教程11 TestNG运行JUnit测试
现在,您已经了解了TestNG和它的各种测试,如果现在担心如何重构现有的JUnit代码,那就没有必要,使用TestNG提供了一种方法,从JUnit和TestNG按照自己的节奏.也可以使用TestNG执 ...
- iOS开发--图片轮播
直接上代码了,比较简单.演示下载地址:Demo // // UYViewController.m // 图片轮播器 // // Created by jiangys on 15/5/23. // Co ...
- VUE滚动条插件——vue-happy-scroll
最近自己在自学vue2.0,然后就自己摸索做一个简单的后台管理系统,在做的过程中,总感觉不同浏览器自带的滚动条样式不统一,也很难看,所以就在网上找一些使用vue的滚动条插件.最开始用的是Easy-sc ...
- Lower Power with CPF(三)
常用的一些Lower Power的策略: 1)Clock tree optimization and clock gating:在正常情况下clock信号会一直toggle at the maximu ...
- VS2010/MFC编程入门之四十四(MFC常用类:定时器Timer)
前面一节鸡啄米讲了CTime类和CTimeSpan类的使用,本节继续讲与时间有关的定时器.定时器并不是一个类,主要考虑到,提起时间的话就不能不说定时器,所以就把它放到CTime和CTimeSpan之后 ...
- charles 手机抓包 unknown
设置通配符即可 需要注意的点: 手机配置好电脑的服务器ip和端口号后,下载证书和安装好,然后电脑也需要安装证书.再配置可允许ssl 本地域名.