传送门:BestCoder Round #88

分析:

A题统计字符串中连续字串全为q的个数,预处理以下或加个cnt就好了;

代码:

 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
using namespace std; #define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define Rof(i,a,b) for (int i=(a),_##i=(b); i>=_##i; i--)
#define rek(i,a,b) for (int i=(a),_##i=(b); i>=_##i; i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define cpy(a,b) memcpy(a,b,sizeof(b))
#pragma comment(linker, "/STACK:102400000,102400000")
inline void read(int &x){x=; char ch=getchar();while(ch<'') ch=getchar();while(ch>=''){x=x*+ch-; ch=getchar();}}
char s[];
int t,cnt;
ll sum;
int main()
{
for(scanf("%d",&t);t--;)
{
scanf("%s",s);int len=strlen(s);cnt=sum=;
for(int i=;i<len;++i) if(s[i]=='q') sum+=cnt,cnt++;else if(cnt) {sum+=cnt;cnt=;}
if(cnt) sum+=cnt;
printf("%lld\n",sum);
}
return ;
}

B题求出一个数字串的所有完全阿贝尔周期;

设S是一个数字串,定义函数occ(S,x)occ(S,x)表示S中数字x的出现次数。

例如:S=(1,2,2,1,3),occ(S,1)=2,occ(S,2)=2,occ(S,3)=1S=(1,2,2,1,3),occ(S,1)=2,occ(S,2)=2,occ(S,3)=1。

如果对于任意的i,都有occ(u,i)=occ(w,i)occ(u,i)=occ(w,i),那么我们认为数字串u和w匹配。

例如:(1,2,2,1,3)\approx(1,3,2,1,2)(1,2,2,1,3)≈(1,3,2,1,2)。

对于一个数字串S和一个正整数k,如果SS可以分成若干个长度为k的连续子串,且这些子串两两匹配,那么我们称k是串S的一个完全阿贝尔周期。

给定一个数字串S,请找出它所有的完全阿贝尔周期

那么对于给定的n,从1-n枚举它的因子比如k,然后判断1-k是否与k+1~2*k,2*k+1~3*k...(t*k<=n)匹配,这里要处理一下,详情见代码
 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
using namespace std; #define LL long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define Rof(i,a,b) for (int i=(a),_##i=(b); i>=_##i; i--)
#define rek(i,a,b) for (int i=(a),_##i=(b); i>=_##i; i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define cpy(a,b) memcpy(a,b,sizeof(b))
#pragma comment(linker, "/STACK:102400000,102400000")
inline void read(int &x){x=; char ch=getchar();while(ch<'') ch=getchar();while(ch>=''){x=x*+ch-; ch=getchar();}}
int t,n,cnt,a[],b[],p[],p1[];
int main()
{
for(scanf("%d",&t);t--;)
{
scanf("%d",&n);cnt=;
F(i,,n) scanf("%d",a+i);
for(int i=;i*i<=n;++i) if(n%i==)
{
for(int i=;i<=n;++i) p[i]=p1[i]=;
int x=n/i;
for(int j=;j<=i;++j) p[a[j]]++;
for(int k=i*;k<=n;k+=i)
{
for(int j=k-i+;j<=k;j++) p1[a[j]]++;
for(int j=;j<=i;++j) if(p[a[j]]*(k/i-)!=p1[a[j]]) goto l;
}
b[cnt++]=i;l:;
for(int i=;i<=n;++i) p[i]=p1[i]=;
for(int j=;j<=x;++j) p[a[j]]++;
for(int k=x*;k<=n;k+=x)
{
for(int j=k-x+;j<=k;j++) p1[a[j]]++;
for(int j=;j<=x;++j) if(p[a[j]]*(k/x-)!=p1[a[j]]) goto l1;
}
b[cnt++]=x;l1:;
}
sort(b,b+cnt);
printf("%d",b[]);
for(int i=;i<cnt;++i) if(b[i]!=b[i-])printf(" %d",b[i]);puts("");
}
return ;
}
 

BestCoder Round #88的更多相关文章

  1. HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力)

    HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=59 ...

  2. bestcoder Round #7 前三题题解

    BestCoder Round #7 Start Time : 2014-08-31 19:00:00    End Time : 2014-08-31 21:00:00Contest Type : ...

  3. BestCoder Round #89 02单调队列优化dp

    1.BestCoder Round #89 2.总结:4个题,只能做A.B,全都靠hack上分.. 01  HDU 5944   水 1.题意:一个字符串,求有多少组字符y,r,x的下标能组成等比数列 ...

  4. BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元

    BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy  Init函数 然后统计就ok B. 博弈 题  不懂  推了半天的SG.....  结果这 ...

  5. Bestcoder round #65 && hdu 5593 ZYB's Tree 树形dp

    Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...

  6. Bestcoder round #65 && hdu 5592 ZYB's Premutation 线段树

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...

  7. 暴力+降复杂度 BestCoder Round #39 1002 Mutiple

    题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...

  8. 贪心 BestCoder Round #39 1001 Delete

    题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...

  9. BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)

    Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

随机推荐

  1. Back to Back Order Process

    Steps involved involved in back to back order process in oracle apps 1. Enter Sales Order 2. Book Sa ...

  2. cdoj 1324 卿学姐与公主 线段树裸题

    卿学姐与公主 Time Limit: 2000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit St ...

  3. 台湾P2P平台

    2014年6月28日下午1:30,“2014两岸三地P2P网贷行业高峰论坛”在上海会展中心友谊会堂如期举行,现场高朋满座,来自全国各地的众多知名P2P网站平台的负责人参与了讨论,并就当前P2P行业的一 ...

  4. 函数fsp_fill_free_list

    /**********************************************************************//** Puts new extents to the ...

  5. Android Studio插件

    awesome-android-ui(UI范例库) https://github.com/wasabeef/awesome-android-ui/tree/master/pages LMBanners ...

  6. UVa 1626 (输出方案) Brackets sequence

    正规括号序列定义为: 空序列是正规括号序列 如果S是正规括号序列,那么[S]和(S)也是正规括号序列 如果A和B都是正规括号序列,则AB也是正规括号序列 输入一个括号序列,添加尽量少的括号使之成为正规 ...

  7. 【英语】Bingo口语笔记(27) - 如何培养口语语感

  8. 【英语】Bingo口语笔记(43) - u长短音

  9. 【英语】Bingo口语笔记(55) - work系列

  10. 收集些日本的VPS

    http://www.serverqueen.jp/service/vps.html http://www.seeds.ne.jp http://dream.jp/vps/ http://fc2-vp ...