zoukankan      html  css  js  c++  java
  • whust #0.1 I

    I - Laughing Out Loud
    Time Limit:1000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u

    Description

    standard input/output 

    Little Toojee was a happy go lucky boy. He seemed to find most, if not all, things funny. One day he read a word and started laughing a lot. Turns out that the word consisted only of the letters L and O. Whenever he saw the subsequence LOL’ in the word, he laughed for 1 second. Given t strings, find out for how long Toojee laughed on seeing each string.

    Input

    The first line contains t queries. This is followed by t lines each containing one string S. String S consists only of capital alphabets.

    Output

    Output for each string on a new line.

    Constraints

    •  ≤ t ≤ 10
    •  ≤ |S| ≤ 105

    Sample Input

    Input
    2
    LOL
    LOLOL
    Output
    1
    4

    Hint

    Test1: On observation, we can tell that there is only 1 occurrence of LOL.

    Test2: Let the string be 0-indexed and let V = {a, b, c} denote the indices that make up the string LOL”, where a is index of the 1st L’, b is index of the O’ and c is the index of the 2nd L’. So, V can be {0, 1, 2}, {2, 3, 4}, {0, 1, 4} and {0, 3, 4}. We see that there are 4 occurrences of the string “LOL”.

    又是求有多少种组合的题.

    和上次cf那道求等比数列的非常像.

     1 /*************************************************************************
     2     > File Name: code/whust/#0.1/II.cpp
     3     > Author: 111qqz
     4     > Email: rkz2013@126.com 
     5     > Created Time: 2015年08月09日 星期日 16时00分44秒
     6  ************************************************************************/
     7 
     8 #include<iostream>
     9 #include<iomanip>
    10 #include<cstdio>
    11 #include<algorithm>
    12 #include<cmath>
    13 #include<cstring>
    14 #include<string>
    15 #include<map>
    16 #include<set>
    17 #include<queue>
    18 #include<vector>
    19 #include<stack>
    20 #define y0 abc111qqz
    21 #define y1 hust111qqz
    22 #define yn hez111qqz
    23 #define j1 cute111qqz
    24 #define tm crazy111qqz
    25 #define lr dying111qqz
    26 using namespace std;
    27 #define REP(i, n) for (int i=0;i<int(n);++i)  
    28 typedef long long LL;
    29 typedef unsigned long long ULL;
    30 const int inf = 0x7fffffff;
    31 int main()
    32 {
    33     int T;
    34     cin>>T;
    35     string st;
    36     while (T--)
    37     {
    38     cin>>st;
    39     int len = st.length();
    40     LL p=0,q=0;
    41     LL ans = 0 ;
    42     for ( int i = 0 ; i < len ; i ++)
    43     {
    44         if (st[i]=='L')
    45         {
    46         p++;
    47         ans = ans + q;
    48         }
    49         else
    50         {
    51         q = q+ p; //p为L的个数,q表示前面有"LO"组合的个数
    52         }
    53     }
    54     cout<<ans<<endl;
    55     }
    56   
    57     return 0;
    58 }
    View Code
  • 相关阅读:
    C++中的名字重整技术
    Linux下C++开发常用命令
    《Effective C++(第三版)》 的55条建议
    我也介绍下sizeof与strlen的区别
    POJ
    HDU
    HDU-1754-I Hate It(单点更新+区间查询)
    HDU多校1003-Divide the Stones(构造)
    Just an Old Puzzle(2019多校1007)
    Idiomatic Phrases Game(最短路+注意坑点)
  • 原文地址:https://www.cnblogs.com/111qqz/p/4715312.html
Copyright © 2011-2022 走看看