传送门: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. 35.3wCF编程

    1.新建一个空白的解决方案文件,然后添加新建项目,项目类型为WCF服务应用程序,CH35Ex01 2.添加新建控制台应用程序Ch35Ex01Client 3.生成解决方案 4.右键Ch35Ex01Cl ...

  2. leetcode:Reverse Linked List II

    Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...

  3. listview android:cacheColorHint,android:listSelector属性作用

      ListView是常用的显示控件,默认背景是和系统窗口一样的透明色,如果给ListView加上背景图片,或者背景颜色时,滚动时listView会黑掉, 原因是,滚动时,列表里面的view重绘时,用 ...

  4. gitflow workflow

    https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow Dream big, work smart,  ...

  5. 【笨嘴拙舌WINDOWS】字符类型与字符串

    "我将用C语言作为工具,开始WINDOWS API的使用" windows NT 从底层开始支持unicode. 1.字符类型 WINDOWS的字符类型在WINNT.H和CTYPE ...

  6. Couchbase的web管理员后台 查看缓存提示警告 Warning: Editing of document with size more than 2.5kb is not allowed的解决方法

    这个警告仅仅只会发生在web管理员后台,实际在缓存中的数据是不会有影响的(好像默认单个key对应的缓存大小是20M) 但是有时候我们就是想在web后台里面看看到底保存了什么数据,怎么能突破这个限制呢? ...

  7. python编码问题(1)

    一.字符编码基础 字符编码是计算机对字符的格式化,从而能够在计算机系统中存储与传输. 1.ASCII码 在计算机内部,所有的信息最终都表示为一个二进制的字符串.每一个二进制位(bit)有0和1两种状态 ...

  8. *ecsho 的商品详细页面上获取该商品的一级分类ID及NAME

    1.打开goods.php并找到 $smarty->assign('goods', $goods); 在它上面增加以下代码 $cat_arr = get_parent_cats($goods[' ...

  9. Hibernate-Native SQL

    1.标量(值)查询: sess.createSQLQuery("SELECT * FROM CATS").list(); sess.createSQLQuery("SEL ...

  10. IconRes提供免费高质量的Material风格android官方图标库

    连接地址: http://www.iconres.com/android/index.php