One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimumjump 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 following letters are vowels: 'A', 'E', 'I', 'O', 'U' and 'Y'.
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.
Print single integer a — the minimumjump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
ABABBBACFEYUKOTT
4
AAA
1
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<stack>
#include<math.h>
#define INF 0x3f3f3f3f
using namespace std;
int dp[2009];
int a[2010],d[2010];
char s[200];
int main()
{
gets(s);
int len=strlen(s);
int ans=1;
int maxx=0;
for(int i=0;i<len;i++)
{
if(s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U'||s[i]=='Y')
ans=1;
else
ans++;
maxx=max(maxx,ans);
}
printf("%d\n",maxx);
}
Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits begin to march, so it is only important how many soldiers march in step.
There will be n columns participating in the parade, thei-th column consists of li soldiers, who start to march from left leg, andri soldiers, who start to march from right leg.
The beauty of the parade is calculated by the following formula: ifL is the total number of soldiers on the parade who start to march from the left leg, andR is the total number of soldiers on the parade who start to march from the right leg, so the beauty will equal|L - R|.
No more than once you can choose one column and tellall the soldiers in this column to switch starting leg, i.e. everyone in this columns who starts the march from left leg will now start it from right leg, and vice versa. Formally, you can pick no more than one indexi and swap values li andri.
Find the index of the column, such that switching the starting leg for soldiers in it will maximize the the beauty of the parade, or determine, that no such operation can increase the current beauty.
The first line contains single integer n (1 ≤ n ≤ 105) — the number of columns.
The next n lines contain the pairs of integersli andri (1 ≤ li, ri ≤ 500) — the number of soldiers in the i-th column which start to march from the left or the right leg respectively.
Print single integer k — the number of the column in which soldiers need to change the leg from which they start to march, or0 if the maximum beauty is already reached.
Consider that columns are numbered from 1 to n in the order they are given in the input data.
If there are several answers, print any of them.
3
5 6
8 9
10 3
3
2
6 5
5 6
1
6
5 9
1 3
4 8
4 5
23 54
12 32
0
In the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5.
If you give the order to change the leg to the third column, so the number of soldiers, who march from the left leg, will equal5 + 8 + 3 = 16, and who march from the right leg — 6 + 9 + 10 = 25. In this case the beauty equals |16 - 25| = 9.
It is impossible to reach greater beauty by giving another orders. Thus, the maximum beauty that can be achieved is 9.
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<stack>
#include<math.h>
#define INF 0x3f3f3f3f
using namespace std;
int dp[2009];
const int maxn=100000+10;
int r[maxn],l[maxn];
char s[200];
int main()
{
int k;
int suml=0,sumr=0;
scanf("%d",&k);
for(int i=1;i<=k;i++)
{
scanf("%d%d",&l[i],&r[i]);
suml+=l[i];
sumr+=r[i];
}
int ans=abs(suml-sumr);
int flag=0;
for(int i=1;i<=k;i++)
{
int c=abs(suml-sumr+2*(r[i]-l[i]));
if(c>ans)
{
ans=c;
flag=i;
}
}
printf("%d\n",flag);
}
补题中。。。。。