bzoj4236 JOIOJI
来源:互联网 发布:mysql 查看阻塞 编辑:程序博客网 时间:2024/06/11 22:14
题目
显然转化为前缀再看相等即可。
sj[j]-sj[i]==so[j]-so[i]==si[j]-si[i]
转化一下
(sj[j]-so[j])-(sj[j]-so[i])==(si[j]-so[j])-(si[i]-so[i])
这样,就转化成两维的了,排一下序就可以统计出来了。
#include<bits/stdc++.h>#define N 200005using namespace std;int n,sj[N+1],so[N+1],si[N+1],ans,last;struct data{ int x; int y; int id;};data A[N+1];char x;inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}inline int read(){ int x=0,b=1; char c=nc(); for(;!(c<='9'&&c>='0');c=nc())if(c=='-')b=-1; for(;c<='9'&&c>='0';c=nc())x=x*10+c-'0'; return x*b;}inline char get(){ char c=nc(); for(;!(c<='Z'&&c>='A');)c=nc(); return c;}inline bool cmp(const data &A,const data &B){ if(A.x!=B.x)return A.x<B.x; if(A.y!=B.y)return A.y<B.y; return A.id<B.id;}int main(){ //freopen("in.txt","r",stdin); n=read(); for(int i=1;i<=n;i++) { x=get(); sj[i]=sj[i-1]+(x=='J'); si[i]=si[i-1]+(x=='I'); so[i]=so[i-1]+(x=='O'); } for(int i=0;i<=n;i++) { A[i].x=si[i]-so[i]; A[i].y=sj[i]-so[i]; A[i].id=i; } sort(A,A+n+1,cmp); ans=0,last=0; for(int i=1;i<=n;i++) if(A[i].x==A[i-1].x&&A[i].y==A[i-1].y)ans=max(A[i].id-A[last].id,ans); else last=i; cout<<ans; return 0;}
阅读全文
0 0
- [BZOJ4236] JOIOJI
- 【BZOJ4236】JOIOJI
- BZOJ4236: JOIOJI
- bzoj4236 JOIOJI
- 数学-bzoj4236: JOIOJI
- 【BZOJ4236】JOIOJI【数学】【排序】【乱搞】
- hash——BZOJ4236 JOIOJI
- JOIOJI
- 4236: JOIOJI
- 【bzoj4236】【JOIJOI】【map】
- [Hash] BZOJ 4236 JOIOJI
- bzoj 4236: JOIOJI
- BZOJ 4236 JOIOJI
- 【BZOJ】4236 JOIOJI
- BZOJ 4236 JOIOJI
- BZOJ 4236 JOIOJI
- BZOJ 4236: JOIOJI
- BZOJ 4236: JOIOJI
- bzoj1202 [HNOI2005]狡猾的商人
- bzoj1213 [HNOI2004]高精度开根
- 【算法入门】深度优先搜索(DFS)
- bzoj1143 [CTSC2008]祭祀river
- bzoj3555 [Ctsc2014]企鹅QQ
- bzoj4236 JOIOJI
- bzoj1191 [HNOI2006]超级英雄Hero
- 社会正在呼吁正确的价值观
- bzoj1263 [SCOI2006]整数划分
- java 学习路线(摘自某培训机构网站)
- hdu 1548 bfs
- HiveQL语法一览
- ROS小课堂的所有教程文档
- 【DB笔试面试1-100】