【HDU 5944 Fxx and string】+ 优化
来源:互联网 发布:美军软件人机界面标准 编辑:程序博客网 时间:2024/06/08 07:24
Fxx and string
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 424 Accepted Submission(s): 193
Problem Description
Young theoretical computer scientist Fxx get a string which contains lowercase letters only.
The string S contains n lowercase letters S1S2…Sn.Now Fxx wants to know how many three tuple (i,j,k) there are which can meet the following conditions:
1、i,j,k are adjacent into a geometric sequence.
2、Si=’y’,Sj=’r’,Sk=’x’.
3.Either j|i or j|k
Input
In the first line, there is an integer T(1≤T≤100) indicating the number of test cases.
T lines follow, each line contains a string, which contains only lowercase letters.(The length of string will not exceed 10000).
Output
For each case, output the answer.
Sample Input
2
xyyrxx
yyrrxxxxx
Sample Output
0
2
正反个判断一次~~~注意优化~~
AC代码 :
#include<bits/stdc++.h>char st[10010];int main(){ int T; scanf("%d",&T); while(T--){ int ans = 0; scanf("%s",st + 1); int nl = strlen(st + 1); for(int i = 1 ; i < nl ; i++) if(st[i] == 'y'){ for(int j = i * 2 ; j < nl ; j += i) if(st[j] == 'r'){ int a = j / i * j; if(a <= nl && st[a] == 'x') ans++; } } for(int i = 1 ; i < nl ; i++) if(st[i] == 'x'){ for(int j = i * 2 ; j < nl ; j += i) if(st[j] == 'r'){ int a = j / i * j; if(a <= nl && st[a] == 'y') ans++; } } printf("%d\n",ans); } return 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
- maven所遇到的坑之打包src中的.xml缺失问题
- python3爬取1024图片
- codevs 2598 编辑距离问题
- Centos6.5中redis的搭建
- 简单封装学习
- 【HDU 5944 Fxx and string】+ 优化
- Remove Linked List Elements
- Kafka快速上手
- Linux内核开发一些系统函数的说明整理
- 阅读(书籍收集)
- linux md5 加密字符串和文件方法
- [C++杂谈]C++的多态
- Shell编程中的数组定义、遍历
- 适配Android N Multi-Window (多窗口)遇到的一些问题