Young theoretical computer scientist Fxx get a string which contains lowercase letters only.
The string S S contains n n lowercase letters S1S2…Sn S1S2…Sn.Now Fxx wants to know how many three tuple (i,j,k) (i,j,k) there are which can meet the following conditions:
1、 i,j,k i,j,k are adjacent into a geometric sequence.
2、 Si= Si=' y y' ,Sj= ,Sj=' r r' ,Sk= ,Sk=' x x'.
3.Either j|i or j|k
The string S S contains n n lowercase letters S1S2…Sn S1S2…Sn.Now Fxx wants to know how many three tuple (i,j,k) (i,j,k) there are which can meet the following conditions:
1、 i,j,k i,j,k are adjacent into a geometric sequence.
2、 Si= Si=' y y' ,Sj= ,Sj=' r r' ,Sk= ,Sk=' x x'.
3.Either j|i or j|k
T T lines follow, each line contains a string, which contains only lowercase letters.(The length of string will not exceed 10000 10000).
2 xyyrxx yyrrxxxxx
02
这个题大致意思是说找等比数列的序列 要考虑到程序的精简 注意不要超时,可以枚举比例,这个会节省很
多时间.
#include<stdio.h> #include<string.h> #include<math.h> #include<iostream> using namespace std; int main() { int t; char a[10005]; scanf("%d",&t); while(t--) { getchar(); scanf("%s",a+1); int i,j,k; int num=0,l; l=strlen(a+1); for(i=1;i<=l;i++) { for(int bi=2;;bi++) { j=i*bi; k=j*bi; if(k>l) break; if(a[i]=='y'&&a[j]=='r'&&a[k]=='x') num++; if(a[i]=='x'&&a[j]=='r'&&a[k]=='y') num++; } } printf("%d\n",num); } return 0; }