传送门

Fxx and string

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

Description

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

02

思路

题意:青年理论计算机科学家Fxx得到了一个只包含小写字母的字符串。字符串的长度为n,下标从1开始,第 i 位的字母为s​i​​,现在Fxx想知道有多少三元组(i,j,k)满足下列条件

  • 1、i,j,k三个数成等比数列
  • 2、si​​='y',sj='r',sk='x'
  • 3.i  j 和k j 中必须有整数

题解:直接暴力枚举,重点在于选择合适的枚举量,如果去暴力字符串的话,肯定T,但是枚举公比的话,效率大大的提高,因为其增长速度很快

 
#include<bits/stdc++.h>
using namespace std;
const int maxn = 10005;
char str[maxn];

int main()
{
	//freopen("input.txt","r",stdin);
	int T;
	scanf("%d",&T);
	while (T--)
	{
		scanf("%s",str+1);
		int len = strlen(str+1);
		int res = 0;
		for (int i = 1;i <= len && i <= len/4;i++)
		{
			for (int j = 2;i*j*j <= len;j++)
			{
				if (str[i] == 'y' && str[i*j] == 'r' && str[i*j*j] == 'x')	res++;
				if (str[i] == 'x' && str[i*j] == 'r' && str[i*j*j] == 'y')	res++;
			}
		}
		printf("%d\n",res);
	}
	return 0;
}

  

 
 

HDU 5944 Fxx and string(暴力/枚举)的更多相关文章

  1. HDU 5944 Fxx and string (暴力)

    题意:给定一个字符串,问有多少个三元组满足 i, j, k组成一个等比数列,并且s[i] = 'y', s[j] = 'r', s[k] = 'x',且j/i ,j/k中至少一个是整数. 析:直接暴力 ...

  2. hdu 5944 Fxx and string

    \:nn,下标从1开始,第\:i\:i位的字母为\:s_is​i​​,现在Fxx想知道有多少三元组\:(i,j,k)\:(i,j,k)满足下列条件 1.i,j,k\:i,j,k三个数成等比数列 2.s ...

  3. hdu 4445 Crazy Tank (暴力枚举)

    Crazy Tank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. HDU 4770 Lights Against Dudely 暴力枚举+dfs

    又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ cz ...

  5. hdu 1172 猜数字(暴力枚举)

    题目 这是一道可以暴力枚举的水题. //以下两个都可以ac,其实差不多一样,呵呵 //1: //4 wei shu #include<stdio.h> struct tt { ],b[], ...

  6. HDU 4431 Mahjong (DFS,暴力枚举,剪枝)

    题意:给定 13 张麻将牌,问你是不是“听”牌,如果是输出“听”哪张. 析:这个题,很明显的暴力,就是在原来的基础上再放上一张牌,看看是不是能胡,想法很简单,也比较好实现,结果就是TLE,一直TLE, ...

  7. HDU 1270 小希的数表 (暴力枚举+数学)

    题意:... 析:我们可以知道,a1+a2=b1,那么我们可以枚举a1,那么a2就有了,并且a1+a3=b2,所以a3就有了,我们再从把里面的剩下的数两两相加,并从b数组中去掉, 那么剩下的最小的就是 ...

  8. HDU 4930 Fighting the Landlords(暴力枚举+模拟)

    HDU 4930 Fighting the Landlords 题目链接 题意:就是题中那几种牌型.假设先手能一步走完.或者一步让后手无法管上,就赢 思路:先枚举出两个人全部可能的牌型的最大值.然后再 ...

  9. hdu 5491 The Next(暴力枚举)

    Problem Description Let L denote the number of 1s in integer D’s binary representation. Given two in ...

随机推荐

  1. SVG入门

    这部分包括三个内容: 1. 基本图形 2. 基本属性 3. 基础操作API 基本图形 名称 描述 参数 图示 rect 定义一个矩形 x="矩形的左上角的x轴" y="矩 ...

  2. Android Studio快速开发之道

    概述 现如今开发越来越追求效率和节奏,节省出时间做更多的事情,除了开发技术上的封装等,开发工具的使用技巧也是很重要的,今天就根据自己的经验来给大家介绍一下Android Studio快速开发之道. P ...

  3. Android MVP 设计模式

    1.基本概念 Model    : 模型   负责处理数据的加载或者存储,比如从网络或本地数据库获取数据等: View     : 视图    负责界面数据的展示,与用户进行交互: Presenter ...

  4. [Erlang 0121] 当我们谈论Erlang Maps时,我们谈论什么 Part 3

    Erlang/OTP 17.0 has been released  http://www.erlang.org/download/otp_src_17.0.readme     Erlang/OTP ...

  5. 转载 c# 颜色对照表

    这篇文章来来源于C# Color Table,这里是我翻译的中文版本,其中已经加上了我的一些理解和注释.翻译这篇文章的原因是我在写C#程序的时候发现,C#自带的颜色种类极多(详见下表),如果没有直观的 ...

  6. sql2008“备份集中的数据库备份与现有的xx数据库不同”解决方法

    http://www.cnblogs.com/huangfr/archive/2012/08/09/2629687.html 因为是在另一台电脑对同名数据库做的备份,用常规方法还原,提示不是相同数据库 ...

  7. 有理数的稠密性(The rational points are dense on the number axis.)

    每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.

  8. [LeetCode] Lowest Common Ancestor of a Binary Tree 二叉树的最小共同父节点

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...

  9. [LeetCode] Path Sum 二叉树的路径和

    Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...

  10. [LeetCode] Same Tree 判断相同树

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...