BZOJ 4236: JOIOJI MAP
4236: JOIOJI
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://www.lydsy.com/JudgeOnline/problem.php?id=4236
Description
Input
Output
Sample Input
10
JOIIJOJOOI
Sample Output
HINT
题意
题解:
我们用前缀和的东西统计到这个位置一共有多少个J,O,I。
假设A[i],B[i],C[i]表示前i个位置分别有多少个J,O,I。
那么只要找到一队A[j]-B[j]==A[i]-B[i],而且B[j]-C[j]==B[j]-C[j]就好了
化简之后就是A[j]-A[i]=B[j]-B[i],B[j]-B[i]=C[j]-C[i]
用一个MAP来维护一下就好了
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 204051
#define mod 10007
#define eps 1e-9
int Num;
//const int inf=0x7fffffff; //§ß§é§à§é¨f§³
const int inf=0x3f3f3f3f;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** char s[maxn];
map<pair<int,int> ,int> H;
int ans=;
int A,B,C;
int main()
{
int n=read();
scanf("%s",s+);
H[make_pair(,)]=;
for(int i=;i<=n;i++)
{
if(s[i]=='J')
A++;
if(s[i]=='O')
B++;
if(s[i]=='I')
C++;
if(H.find(make_pair(A-B,B-C))==H.end())
H[make_pair(A-B,B-C)]=i;
else
ans = max(ans,i-H[make_pair(A-B,B-C)]);
}
printf("%d\n",ans);
}
BZOJ 4236: JOIOJI MAP的更多相关文章
- BZOJ 4236: JOIOJI map瞎搞
分别记录J,O,I,的个数 cnt[char][i] 表示处理到第i位,char的个数 显然当且仅当 cnt[J][i] - cnt[O][i] == cnt[J][j-1] - cnt[O][j-1 ...
- BZOJ 4236 "JOIOJI"(前缀和+map+pair)
传送门: [1]:BZOJ [2]:洛谷 •题解 定义数组 a,b,c 分别表示 'J' , 'O' , 'I' 的前缀和: 要想使区间 (L,R] 满足条件当且仅当 a[R]-a[L] = b[R] ...
- bzoj 4236: JOIOJI【前缀和+map】
设sj,so,si分别是J O I的个数前缀和,然后要求求最长(l,r)满足sj[r]-sj[l-1]==so[r]-so[l-1]==si[r]-si[l-1],化简一下就是满足so[r]-so[l ...
- BZOJ 4236 JOIOJI(前缀和)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4236 [题目大意] 给出一个只包含三种字母的字符串,求出三种字母数量相等的最长子串 [ ...
- BZOJ 4236: JOIOJI
Description 给出一个字符串,只包含3个字母,询问最长的一个子串,3个字母出现次数相同. Sol map. 如果一个子串满足条件,那么它端点处的三个字母的个数两两差值都是一样的,直接存个状态 ...
- BZOJ 4236~4247 题解
BZOJ 4236 JOIOJI f[i][0..2]表示前i个字符中′J′/′O′/′I′的个数 将二元组<f[i][0]−f[i][1],f[i][1]−f[i][2]>扔进map,记 ...
- BZOJ 4236 set乱搞
思路: 取个差 在set里面找 更新 (这个用map更好吧 但是我不会--) //By SiriusRen #include <set> #include <cstdio> # ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 【BZOJ】【2242】【SDOI2011】计算器
快速幂/扩展欧几里得/BSGS 经典好例题!! 三个问题三种算法…… 算法:白书(算法竞赛入门经典——训练指南)全有…… /************************************** ...
随机推荐
- 多线程监控文件夹,FlieSystemWatcher,并使用共享函数
发表于: 2011-01-06 09:55:47 C# code ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 2 ...
- mysql索引与优化
mysql 索引与优化 http://www.cnblogs.com/hustcat/archive/2009/10/28/1591648.html
- HDU 5882 Balanced Game
Balanced Game Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu 1175(广搜)
题意:容易理解... 思路:我开始的思路不好实现,而且有漏洞,时间复杂度也高,后来在网上学了下别人的方法,真心感觉很牛B,不仅代码好实现,而且时间复杂度比较低,具体看代码实现吧!! 代码实现: #in ...
- [C++]cin读取回车键
最近碰到一个问题,就是从控制台读取一组数,如: 12 23 34 56 若是使用 int data; while ( cin >> data ) {//...} 当回车后,不能有效转换到后 ...
- ASPNET中实现在线用户检测(使用后台守护线程)
启动后台线程可以用下面的语句:CheckOnline online=new CheckOnline(); 用户可以将它放到GLOBAL.ASAX中,我是没有了,只放到了一个ASPX文件中做简单的测试. ...
- 【转载】cocos2d-x教程 Mac系统下搭建Lua的编码环境
原文链接:http://blog.csdn.net/u012945598/article/details/17168831 在使用Lua写脚本的时候大家都会因为没有代码提示导致敲代码的效率有所下降 ...
- 谈谈作为一个菜B的培训感受
培训的目的是为了让新员工更快的适应当前的工作,尽快的跟上前辈的步伐,从而能全身心的投入到当前的工作当中.感觉在培训的时候需要注意以下的几个问题: 1. 新员工必须在意识上认同当前的工作 如今的项目组也 ...
- 线段和矩形相交 POJ 1410
// 线段和矩形相交 POJ 1410 // #include <bits/stdc++.h> #include <iostream> #include <cstdio& ...
- Creating Help Pages for ASP.NET Web API -摘自网络
When you create a web API, it is often useful to create a help page, so that other developers will k ...