JOJ2519 Find the longest section(位运算 +(前缀和?))
来源:互联网 发布:西康路855半梦会所 js 编辑:程序博客网 时间:2024/05/21 19:39
找一个最长字符串区间,满足里面每个字母出现的次数为偶数巧妙的利用了位运算的性质将所有的状态存在一个整数里,二进制数的每位是0 1 分别表示字母出现的偶 奇次,在利用前缀和
#include <cstdio>#include <string.h>#include <algorithm>using std::sort;const int maxn=10005;char str[105];int cnt[maxn];int pin[maxn];int assist[maxn];bool cmp(int a,int b){ if(cnt[a]!=cnt[b])return cnt[a]<cnt[b]; return a<b;}int main (){ int n,i,j; int start , end , maxl , tmpl,s,e; while (~scanf("%d",&n)) { memset (cnt,0,sizeof(cnt)); pin[0]=0; for (i=1 ; i<=n ; ++i) { scanf("%s",str); int len =strlen (str); cnt[i]^=cnt[i-1]; for (j=0 ; j<len ; ++j) { cnt[i]^=(1<<(str[j]-'a')); //printf("%d ",cnt[i]); } pin[i]=i; assist[i]=i; } sort(assist , assist+n+1 , cmp); start=end=0;maxl=0; for (i=1 ; i<=n ; ++i) { //printf("%o ",cnt[i]); if(cnt[assist[i]]==cnt[assist[i-1]]) { tmpl=pin[assist[i]]-pin[assist[i-1]]; //printf("t=%d %d %d\n",tmpl,assist[i],assist[i-1]); if(maxl<tmpl) { start=pin[assist[i-1]]; end=pin[assist[i]]; maxl=tmpl; } pin[assist[i]]=pin[assist[i-1]]; } } if(start || end )printf("%d %d\n" ,start+1,end); else printf("No one\n"); } return 0;}
- JOJ2519 Find the longest section(位运算 +(前缀和?))
- 位运算(记录前缀和)
- ZOJ 3591 Nim 前缀和+位运算
- Leetcode#389. Find the Difference(位运算=异或)
- HDU 1595find the longest of the shortest(spfa)
- hdu 1595 find the longest of the shortest (spfa)
- HDU 1595 find the longest of the shortest (Dijkstra)
- hdu 1595 find the longest of the shortest (Dijkstra)
- The Lazy Cow(前缀和)
- HDU1556 color the ball(前缀和)
- USACO section 2.3 Longest Prefix(dp)
- USACO-Section 2.3 Longest Prefix (DP)
- HDU-5980 Find Small A(位运算)
- hdu 5980 Find Small A(位运算思维)
- USACO / Longest Prefix最长前缀(DP)
- Longest Common Prefix(最长公共前缀)
- Longest Common Prefix (最长公共前缀)
- Longest Common Prefix(最长相同前缀)
- HDOJ 1789 Doing Homework again
- 我的那些书
- AS3与JS进行交互(一)
- HDOJ 2037 今年暑假不AC
- Myeclipse配置weblogic服务器
- JOJ2519 Find the longest section(位运算 +(前缀和?))
- 上传kernel 及svn常用命令
- 大型网站架构演变和知识体系
- SVM入门(四)线性分类器的求解——问题的描述Part1
- C++_类模板基础知识
- 制作ide(1)
- 制作ide(2)
- 多校联合第五场北京正常大学BNU 1002 Lucky Numbers(找规律or容斥原理?)
- h4include