zoukankan      html  css  js  c++  java
  • 2019牛客暑期多校训练营(第八场)G Gemstones(模拟)

    链接:https://ac.nowcoder.com/acm/contest/888/G
    来源:牛客网

    题目描述

    Gromah and LZR have entered the seventh level. There are a sequence of gemstones on the wall.

    After some tries, Gromah discovers that one can take exactly three successive gemstones with the same types away from the gemstone sequence each time, after taking away three gemstones, the left two parts of origin sequence will be merged to one sequence in origin order automatically.

    For example, as for "ATCCCTTG", we can take three 'C's away with two parts "AT", "TTG" left, then the two parts will be merged to "ATTTG", and we can take three 'T's next time.

    The password of this level is the maximum possible times to take gemstones from origin sequence.

    Please help them to determine the maximum times.

    输入描述:

    Only one line containing a string ss_{}s, denoting the gemstone sequence, where the same letters are regarded as the same types.
     
     
    1≤∣s∣≤1051 le |s| le 10^51s105
     
    ss_{}s only contains uppercase letters.

    输出描述:

    Print a non-negative integer in a single line, denoting the maximum times.
    示例1

    输入

    复制
    ATCCCTTG

    输出

    复制
    2

    说明

    One possible way is that ‘‘ATCCCTTG "  →  ‘‘ATTTG "  →‘‘AG "``ATCCCTTG\,"  ; 
    ightarrow ; ``ATTTG\," ; 
    ightarrow ``AG\,"ATCCCTTG"ATTTG"AG".
    #include <cstdio>
    #include <iostream>
    #include <cmath>
    #include <string>
    #include <cstring>
    #include <algorithm>
    #include <queue>
    #include <vector>
    #include <map>
    using namespace std;
    
    #define ll long long
    #define eps 1e-9
    
    string s;
    int sign[100000 + 8], num[100000 + 8];
    
    int main()
    {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cin>>s;
        int len = s.size();
        int id = 0;
        int ans = 0;
        memset(num, 0, sizeof(num));
        for(int i = 0; i < len; i++)
        {
            if(!i)
            {
                sign[id] = s[i];
                num[id]++;
            }
            else
            {
                if(s[i] == sign[id])
                {
                    num[id]++;
                    if(num[id] == 3)
                    {
                        num[id] = 0;
                        id--;
                        ans++;
                    }
                }
                else
                {
                    sign[++id] = s[i];
                    num[id]++;
                }
            }
    
        }
        cout << ans << '
    ';
        return 0;
    }
  • 相关阅读:
    C#虚方法
    C#构造方法--实例化类时初始化的方法
    C#抽象类与抽象方法--就是类里面定义了函数而函数里面什么都没有做的类
    C#函数重载
    C#继承
    C#中public与private与static
    FPGA按一下按键,对应端口输出单个脉冲
    MyBatis学习 之 五、MyBatis配置文件
    MyBatis学习 之 四、动态SQL语句
    MyBatis学习 之 三、SQL语句映射文件(2)增删改查、参数、缓存
  • 原文地址:https://www.cnblogs.com/RootVount/p/11368600.html
Copyright © 2011-2022 走看看