zoukankan      html  css  js  c++  java
  • 【非常高%】【codeforces 733A】Grasshopper And the String

    time limit per test1 second
    memory limit per test256 megabytes
    inputstandard input
    outputstandard output
    One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of his jump.

    Formally, consider that at the begginning the Grasshopper is located directly in front of the leftmost character of the string. His goal is to reach the position right after the rightmost character of the string. In one jump the Grasshopper could jump to the right any distance from 1 to the value of his jump ability.

    The picture corresponds to the first example.
    The following letters are vowels: ‘A’, ‘E’, ‘I’, ‘O’, ‘U’ and ‘Y’.

    Input
    The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.

    Output
    Print single integer a — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.

    Examples
    input
    ABABBBACFEYUKOTT
    output
    4
    input
    AAA
    output
    1

    【题解】

    最大长度就是这个字符串的长度;
    枚举一下最大跳跃距离就好;
    100的距离
    怎么样也不会超时了;
    随便写吧;

    #include <cstdio>
    #include <cmath>
    #include <set>
    #include <map>
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <queue>
    #include <vector>
    #include <stack>
    #include <string>
    #define lson L,m,rt<<1
    #define rson m+1,R,rt<<1|1
    #define LL long long
    
    using namespace std;
    
    const int MAXN = 2000;
    const int dx[5] = {0,1,-1,0,0};
    const int dy[5] = {0,0,0,-1,1};
    const double pi = acos(-1.0);
    
    string s1;
    bool can[MAXN];
    
    void input_LL(LL &r)
    {
        r = 0;
        char t = getchar();
        while (!isdigit(t) && t!='-') t = getchar();
        LL sign = 1;
        if (t == '-')sign = -1;
        while (!isdigit(t)) t = getchar();
        while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
        r = r*sign;
    }
    
    void input_int(int &r)
    {
        r = 0;
        char t = getchar();
        while (!isdigit(t)&&t!='-') t = getchar();
        int sign = 1;
        if (t == '-')sign = -1;
        while (!isdigit(t)) t = getchar();
        while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
        r = r*sign;
    }
    
    
    int main()
    {
        //freopen("F:\rush.txt","r",stdin);
        cin >> s1;
        int len = s1.size();
        for (int i = 1;i <= len;i++)
            if (s1[i-1]=='A' || s1[i-1]=='E' || s1[i-1]=='I' || s1[i-1] == 'O' || s1[i-1]=='U' || s1[i-1]=='Y')
                can[i] = true;
        for (int i = len+1;i<= len*3;i++)
            can[i] = true;
        for (int k = 1;k<=len+1;k++)
        {
            int now = 0;
            while (true)
            {
                bool judge = false;
                for (int j = now+k;j>=now+1;j--)
                    if (can[j])
                    {
                        now = j;
                        judge = true;
                        break;
                    }
                if (!judge) break;
                if (now > len)
                {
                    printf("%d
    ",k);
                    return 0;
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    Angular14 Angular相关命令
    Angular14 Visual Studio Code作为Angular开发工具常用插件安装、json-server安装与使用、angular/cli安装失败问题、emmet安装
    Material使用03 MdCardModule模块、MdInputModule模块
    Material使用02 图标MdIconModule、矢量图作为图标使用及改进
    Material使用01 侧边栏MdSidenavModule、工具栏MdTollbarModule
    阿里巴巴Druid数据库连接池的使用
    利用generator自动生成model(实体)、dao(接口)、mapper(映射)
    c++拷贝函数详解(转)
    c++友元函数友元类
    c++中虚函数与纯虚函数的区别(转)
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7632098.html
Copyright © 2011-2022 走看看