zoukankan      html  css  js  c++  java
  • HDU 5944 暴力

    Fxx and string

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


    Problem Description
    Young theoretical computer scientist Fxx get a string which contains lowercase letters only.

    The string S contains n lowercase letters S1S2Sn .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(1T100) 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
     
    Source
     
    题意:
    题解:给你一个字符串暴力求 有多少组 ‘y’ ‘r’ ‘x’ 位置成等比数列  注意逆序!
     1 /******************************
     2 code by drizzle
     3 blog: www.cnblogs.com/hsd-/
     4 ^ ^    ^ ^
     5  O      O
     6 ******************************/
     7 #include<bits/stdc++.h>
     8 #include<map>
     9 #include<set>
    10 #include<cmath>
    11 #include<queue>
    12 #include<bitset>
    13 #include<math.h>
    14 #include<vector>
    15 #include<string>
    16 #include<stdio.h>
    17 #include<cstring>
    18 #include<iostream>
    19 #include<algorithm>
    20 #pragma comment(linker, "/STACK:102400000,102400000")
    21 using namespace std;
    22 #define  A first
    23 #define B second
    24 const int mod=1000000007;
    25 const int MOD1=1000000007;
    26 const int MOD2=1000000009;
    27 const double EPS=0.00000001;
    28 typedef __int64 ll;
    29 const ll MOD=1000000007;
    30 const int INF=1000000010;
    31 const ll MAX=1ll<<55;
    32 const double eps=1e-8;
    33 const double inf=~0u>>1;
    34 const double pi=acos(-1.0);
    35 typedef double db;
    36 typedef unsigned int uint;
    37 typedef unsigned long long ull;
    38 int t;
    39 char a[10005];
    40 int main()
    41 {
    42     scanf("%d",&t);
    43     for(int i=1;i<=t;i++)
    44     {
    45         int sum=0;
    46         scanf("%s",a+1);
    47         int len=strlen(a+1);
    48         for(int j=1;j<=len;j++)
    49         {
    50             if(a[j]=='y')
    51             {
    52                 for(int k=2;;k++)
    53                 {
    54                     if(j*k*k>len)
    55                         break;
    56                     if(a[j*k]=='r'&&a[j*k*k]=='x')
    57                     {
    58                         sum++;
    59                     }
    60                 }
    61             }
    62             if(a[j]=='x')
    63             {
    64                 for(int k=2;;k++)
    65                 {
    66                     if(j*k*k>len)
    67                         break;
    68                     if(a[j*k]=='r'&&a[j*k*k]=='y')
    69                     {
    70                         sum++;
    71                     }
    72                 }
    73             }
    74         }
    75         printf("%d
    ",sum);
    76     }
    77     return 0;
    78 }
     
     
  • 相关阅读:
    函数的返回值与调用
    函数的定义
    文件的高级应用
    文件三种打开模式
    c++0x11新特性:delete删除函数
    网络研发工程师
    cannot find -lGL
    webSocket 使用 HttpSession 的数据配置与写法
    websocket 使用 spring 的service层 ,进而调用里面的 dao层 来操作数据库 ,包括redis、mysql等通用
    redis 重启服务丢失 密码设置 现象 与 解决过程
  • 原文地址:https://www.cnblogs.com/hsd-/p/6013402.html
Copyright © 2011-2022 走看看