向前走莫回头❤

【hdu 5944】Fxx and string(枚举)

Fxx and string

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 603    Accepted Submission(s): 256

 

【题解】【枚举】
【大水题一道。。。然后被卡T】
【显然这个三元组的下标是等比数列,那么枚举三元组的第一个元素和公比q即可。】
【注:q不一定是整数】

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char ch[10010];
int T,len,ans;
int main()
{
    int i;
    scanf("%d\n",&T);
    while(T--)
     {
         gets(ch+1); ans=0;
         len=strlen(ch+1);
         for(int l=2;l*l<=len;++l)
          for(i=1;i<len-1;++i)
           if(i*l*l<=len)
            {
             if(ch[i]=='y')
              {
                    int j=i*l,k=j*l;
                    if(ch[j]=='r'&&ch[k]=='x') ans++;
             }
            if(ch[i]=='x')
             {
                  int j=i*l,k=j*l;
                  if(ch[j]=='r'&&ch[k]=='y') ans++;
             }
           } 
          else break;
        printf("%d\n",ans);
    }
}


posted @ 2016-10-30 21:23  lris0-0  阅读(78)  评论(0编辑  收藏  举报
过去的终会化为美满的财富~o( =∩ω∩= )m