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;
    }
  • 相关阅读:
    appium 方法整理
    appium_获取元素状态
    Locust性能测试_参数关联
    Locust性能测试-参数化批量注册
    pytest_命令行传参
    pytest_函数传参和firture传参数request
    pytest_用例a失败,跳过测试用例b和c并标记失败xfail
    pytest_skip跳过用例
    pytest_使用自定义标记mark
    算法:迷宫问题
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7632098.html
Copyright © 2011-2022 走看看