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的更多相关文章
- HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力)
HDU 5908 Abelian Period (BestCoder Round #88 模拟+暴力) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=59 ...
- bestcoder Round #7 前三题题解
BestCoder Round #7 Start Time : 2014-08-31 19:00:00 End Time : 2014-08-31 21:00:00Contest Type : ...
- BestCoder Round #89 02单调队列优化dp
1.BestCoder Round #89 2.总结:4个题,只能做A.B,全都靠hack上分.. 01 HDU 5944 水 1.题意:一个字符串,求有多少组字符y,r,x的下标能组成等比数列 ...
- BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元
BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy Init函数 然后统计就ok B. 博弈 题 不懂 推了半天的SG..... 结果这 ...
- 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 ...
- Bestcoder round #65 && hdu 5592 ZYB's Premutation 线段树
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...
- 暴力+降复杂度 BestCoder Round #39 1002 Mutiple
题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...
- 贪心 BestCoder Round #39 1001 Delete
题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...
- 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 ( ...
随机推荐
- C语言输出当前日期和时间
#include <stdio.h> #include <time.h> char* asctime2(const struct tm *timeptr) { static c ...
- Python Mongo操作
# -*- coding: utf-8 -*- ''' Python Mongo操作Demo Done: ''' from pymongo import MongoClient conn = None ...
- remove duplicates in Postgres(sql去重)
A frequent question in IRC is how to delete rows that are duplicates over a set of columns, keeping ...
- 使用Aspose.Cells组件生成Excel文件
生成带表头的Excel文件,格式如下显示. 当然更复杂的一些也可以通过 合并单元格的方法 public void Merge(int firstRow, int firstColumn, int to ...
- 微信公共服务平台开发(.Net 的实现)5-------解决access_token过期的问题(转)
因为access_token,在以后的高级功能里面会经常用到,所以这里不得不这里对前面所讲解的access_token改造一下.另外需要说明的是access_token是变化的,有自己的周期,官方解释 ...
- 旧书重温:0day2【3】 详细解读PEB法 查找kener32地址
题外话:上一篇文章中的 PEB法查找kerner32地址的方法 对TEB.PEB .PE结构 知识要求很高,确实在写汇编代码时候小编 感觉自己能力,信手啪啪一顿乱撸,结果一运行,非法访问了,没办法翻阅 ...
- I.MX6 Android backlight modify by C demo
/************************************************************************** * I.MX6 Android backligh ...
- 【英语】Bingo口语笔记(22) - Talk系列
talk back 顶嘴 talk somebody in to something 劝某人做某事 tal somebody out of something 劝某人不做某事
- Javaweb里面的filter,listener,servlet
Filter 1Filter是什么:是过滤器简称 2Filter有什么作用:在filter中可以得到代表用户请求和响应的request.response对象,因此在编程中可以使用Decorator(装 ...
- MySQL server has gone away 的解决方法
原文引用至:http://www.jb51.net/article/23781.htm,感谢! 可能原因:1.发送的SQL语句太长,以致超过了max_allowed_packet的大小,如果是这种原因 ...