【非常高%】【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\n",k);
return 0;
}
}
}
return 0;
}
相关文章
- JS 使用 lz-string存储 数据压缩
- C标准库<string.h>实现
- JAVA中,字符串STRING与STRINGBUILDER的效率差异
- 把Map 转化为query string
- String的replaceAll方法中的正则表达式用法
- Python 自己动手创建string标准库中的常量
- golang方法的使用细节:参数默认是值拷贝,不仅仅是struct自定义数据类型也可以绑定方法、方法名称首字母大写为public权限、String()方法的使用
- Error: String or binary data would be truncated. The statement has been terminated
- Json string to object debug - json字符串转Java对象的处理调试
- Error: String or binary data would be truncated. The statement has been terminated
- Java 分割字符串的方法String.split()底层原理与使用
- 判断String为空 StringUtils工具 isNotEmpty与isNotBlank区别
- Iptables 扩展模块 string|time 模块