# Find Q

Accepts: 392
Submissions: 780
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 262144/131072 K (Java/Others)

Byteasar迷恋上了'q'这个字母。

输入的第一行包含一个正整数T(1≤T≤10)T(1\leq T\leq10)

对于每组数据，输出一行一个整数，即仅包含字母'q'的连续子串的个数。

2
qoder
quailtyqqq

1
7题解:尺取法直接上就好了,要注意数据范围 long long
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <bits/stdc++.h>
using namespace std;
typedef long long  LL;
const int N = 100005;
char str[N];
int main()
{
freopen("a.txt","r",stdin);
int tcase;
scanf("%d",&tcase);
while(tcase--){
scanf("%s",str+1);
int len = strlen(str+1);
LL l = 1,r = 1;
long long cnt = 0;
while(l<=len){
while(l<=len&&str[l]!='q') l++;
r = l;
while(r<=len&&str[r]=='q'){
r++;
}
if(r>l){
cnt+=(r-l)*(r-l+1)/2;
}
l = r;
}
printf("%lld\n",cnt);
}
return 0;
}

# Abelian Period

Accepts: 288
Submissions: 984
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 262144/131072 K (Java/Others)

设SS

输入的第一行包含一个正整数T(1≤T≤10)T(1\leq T\leq10)

对于每组数据，输出一行若干个整数，从小到大输出所有合法的kk

2
6
5 4 4 4 5 4
8
6 5 6 5 6 5 5 6

3 6
2 4 8题解:保存异或前缀异或和 ,k一定是 n的因子,所以枚举的 k不会很多.然后每隔k个比一下当前的异或和和前面异或和的异或值是否为0的就行了.
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <bits/stdc++.h>
using namespace std;
typedef long long  LL;
const int N = 100005;
LL a[N],sum[N];
int factor[N],ans[N];
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--)
{
int n;
scanf("%d",&n);
memset(sum,0,sizeof(sum));
for(int i=1; i<=n; i++)
{
scanf("%I64d",&a[i]);
sum[i] = sum[i-1]^a[i];
}
int id = 0,m = n;
factor[id++] = 1;
for(int i=2; i*i<=n; i++)
{
if(n%i==0)
{
if(i*i==n) factor[id++] = i;
else
{
factor[id++] = n/i;
factor[id++] = i;
}
}
}
factor[id++] = n;
sort(factor,factor+id);
int cnt = 0;
bool flag = false;
for(int j=0; j<id; j++)
{
bool flag = false;
int k = factor[j];
for(int i=2*k; i<=n; i+=k)
{
LL pre = sum[i]^sum[i-k],nxt;
if(i>=2*k) nxt = sum[i-k]^sum[i-2*k];
else nxt = sum[i-k];
if((pre^nxt)!=0) {
flag = true;
break;
}
}
if(!flag) ans[cnt++] = k;
}
flag = true;
for(int i=0;i<cnt;i++){
if(!flag) printf(" %d",ans[i]);
else printf("%d",ans[i]);
flag = false;
}
printf("\n");
}
return 0;
}

posted @ 2016-10-01 21:43  樱花庄的龙之介大人  阅读(388)  评论(0编辑  收藏