zoukankan      html  css  js  c++  java
  • CF 353D

    题意: if at some time the i-th position has a boy and the (i + 1)-th position has a girl, then in a second, the i-th position will have a girl and the (i + 1)-th one will have a boy

    求什么时候不在交换(时间)

    D. Queue

    There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.

    Each second all boys that stand right in front of girls, simultaneously swap places with the girls (so that the girls could go closer to the beginning of the line). In other words, if at some time the i-th position has a boy and the (i + 1)-th position has a girl, then in a second, the i-th position will have a girl and the (i + 1)-th one will have a boy.

    Let's take an example of a line of four people: a boy, a boy, a girl, a girl (from the beginning to the end of the line). Next second the line will look like that: a boy, a girl, a boy, a girl. Next second it will be a girl, a boy, a girl, a boy. Next second it will be a girl, a girl, a boy, a boy. The line won't change any more.

    Your task is: given the arrangement of the children in the line to determine the time needed to move all girls in front of boys (in the example above it takes 3 seconds). Baking buns takes a lot of time, so no one leaves the line until the line stops changing.

    Input

    The first line contains a sequence of letters without spaces s1s2... sn (1 ≤ n ≤ 106), consisting of capital English letters M and F. If letter si equals M, that means that initially, the line had a boy on the i-th position. If letter siequals F, then initially the line had a girl on the i-th position.

    Output

    Print a single integer — the number of seconds needed to move all the girls in the line in front of the boys. If the line has only boys or only girls, print 0.

    Sample test(s)
    input
    MFM
    output
    1
    input
    MMFF
    output
    3
    input
    FFMMM
    output
    0
    Note

    In the first test case the sequence of changes looks as follows: MFM  →  FMM.

    The second test sample corresponds to the sample from the statement. The sequence of changes is: MMFF  → MFMF  →  FMFM  →  FFMM.

    //#pragma comment(linker, "/STACK:102400000")
    #include<cstdlib>
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    #include<algorithm>
    #include<set>
    #include<map>
    #include<list>
    #include<queue>
    #include<vector>
    #define tree int o,int l,int r
    #define lson o<<1,l,mid
    #define rson o<<1|1,mid+1,r
    #define lo o<<1
    #define ro o<<1|1
    #define pb push_back
    #define mp make_pair
    #define ULL unsigned long long
    #define LL long long
    #define inf 0x7fffffff
    #define eps 1e-7
    #define N 1000009
    using namespace std;
    int m,n,T,t,x,y,u;
    char str[N];
    int main()
    {
    #ifndef ONLINE_JUDGE
        freopen("ex.in","r",stdin);
    #endif
        while(scanf("%s",str)==1)
        {
            int ans=0,cnt=0;
            n=strlen(str);
            for(int i=0;i<n;i++)
            {
                if(str[i]=='M')cnt++;
                else if(cnt!=0)
                {
                    ans=max(ans+1,cnt);
                }
            }
            printf("%d
    ",ans);
    
        }
        return 0;
    }
    View Code
  • 相关阅读:
    查找一段信号的累加峰值---verilog
    AXI_stream接口时序温习
    QAM调制---Verilog代码
    数据交织模块---Verilog代码
    卷积编码后的删余模块---Verilog代码
    数据发送模块---基于地址的检测(verilog代码)
    短训练序列---Verilog代码
    长训练序列---verilog代码
    数据扰码器---Verilog代码
    卷积编码器---Verilog代码
  • 原文地址:https://www.cnblogs.com/sbaof/p/3364159.html
Copyright © 2011-2022 走看看