HDU 5944 Fxx and string(数学)
来源:互联网 发布:cntv中国网络电视台5 编辑:程序博客网 时间:2024/06/04 19:57
问题描述
青年理论计算机科学家Fxx得到了一个只包含小写字母的字符串。字符串的长度为n,下标从1开始,第i位的字母为si,现在Fxx想知道有多少三元组(i,j,k)满足下列条件1、i,j,k三个数成等比数列2、si='y',sj='r',sk='x'3.i/j和k/j中必须有整数
输入描述
第一行一个整数T(1≤T≤100)表示数据组数。接下来T行,每行一个仅包含小写字母的字符串(字符串长度不超过10000)
输出描述
输出共T行。每行一个整数表示答案。
输入样例
2xyyrxxyyrrxxxxx
输出样例
02
注意:公比可能小于一
代码如下:
#include<cstdio>#include<cstring>#include<algorithm> using namespace std;char a[100010];int main(){int t;scanf("%d",&t);while(t--){scanf("%s",a);int len=strlen(a); int q,i,j,k; int num=0;for(int p=0;p<len;p++){ int i=p+1; for(q=2;;q++) { j=i*q; k=j*q; if(k>len) break; if(a[i-1]=='y'&&a[j-1]=='r'&&a[k-1]=='x') { num++; } if(a[i-1]=='x'&&a[j-1]=='r'&&a[k-1]=='y')//公比小于1的情况 { num++; } } }printf("%d\n",num);} }
0 0
- HDU 5944 Fxx and string(数学)
- hdu 5944 Fxx and string
- hdu 5944 Fxx and string
- HDU 5944 Fxx and string
- hdu 5944 Fxx and string
- HDU 5944 Fxx and string
- hdu 5944 Fxx and string
- hdu 5944 Fxx and String 暴力(水)
- hdu 5944 Fxx and string【暴力枚举】
- 【HDU 5944 Fxx and string】+ 优化
- 【hdu 5944】Fxx and string(枚举)
- hdu 5944 等比数列 fxx and string
- BestCoder Round #89 1001 /hdu 5944/ Fxx and string
- HDOJ 5944 Fxx and string
- bestcode Fxx and string
- Fxx and string
- HDU5944 Fxx and string
- *Fxx and string
- 今天过了三道基础题,夯实!
- Codeforces 347D - Lucky Common Subsequence
- 站内SEO规范
- codeblocks使用小技巧
- iOS 背景动态图
- HDU 5944 Fxx and string(数学)
- 2016 杭州·云栖大会 PDF 下载 | 那伊抹微笑
- 短信验证的实现
- KVC,KVO
- HDU5917 Instability
- Android 第三方网络框架汇集
- Python & Adb Shell & UiAutomator -- 微信自动发朋友圈/点赞/...
- 怎样控制文章长度利于网站SEO
- OpenCV Tutorial: Harris 角點