codeforces 733A 733B之Grasshopper And the String Parade

codeforces 733A


Description

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 from1 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.

Sample Input

Input
ABABBBACFEYUKOTT
Output
4
Input
AAA
Output

1


题目大意:一只蚂蚱从字符串左边跳到右边,一次只能跳到最近的元音字母上,问它一次最远能跳几步?


TTT 4

ATTTT 5


AC代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn=100+10;

char a[maxn];

bool fun(char a)
{
    if(a=='A' || a=='E' || a=='I' || a=='O' || a=='U' || a=='Y') return 1;
    else return 0;
}

int main()
{
    while(scanf("%s",a)!=EOF)
    {
        int last=-1;
        int maxi=0;
        for(int i=0;i<(int)strlen(a);i++)
        {
            if(fun(a[i]))
            {
                //if(i-last>=maxi)  maxi=i-last;
                maxi=max(maxi,i-last);
                last=i;
            }
            if(i==(int)strlen(a)-1)
            {
                //if(i-last+1>=maxi)  maxi=i-last+1;
                maxi=max(maxi,i-last+1);
            }
        }
        cout<<maxi<<endl;
    }
    return 0;
}


codeforces 733B

Description

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, the i-th column consists of li soldiers, who start to march from left leg, and risoldiers, who start to march from right leg.

The beauty of the parade is calculated by the following formula: if L is the total number of soldiers on the parade who start to march from the left leg, and R 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 tell all 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 index i and swap values li and ri.

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.

Input

The first line contains single integer n (1 ≤ n ≤ 105) — the number of columns.

The next n lines contain the pairs of integers li and ri (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.

Output

Print single integer k — the number of the column in which soldiers need to change the leg from which they start to march, or 0 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.

Sample Input

Input
3
5 6
8 9
10 3
Output
3
Input
2
6 5
5 6
Output
1
Input
6
5 9
1 3
4 8
4 5
23 54
12 32
Output
0

Hint

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 equal 5 + 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.



题意:给你n组数据,问你交换哪一组可以使得两组差值最大?如果差值已经最大,输出0

AC代码:

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

const int maxn=1e5+100;
int l[maxn],r[maxn];

int main()
{
    int n;
    while(cin>>n)
    {
        int left=0;
        int right=0;
        int ans=0;
        bool flag=false;
        for(int i=0;i<n;i++)
        {
            cin>>l[i]>>r[i];
            left+=l[i];
            right+=r[i];
        }
        int maxi=abs(left-right);
        for(int i=0;i<n;i++)
        {
            if(abs( (left-right+r[i]-l[i]) +r[i]-l[i])>maxi)
            {
                flag=true;
                ans=i;
                maxi=abs( (left-right+r[i]-l[i]) +r[i]-l[i]);
            }
        }
        if(!flag) ans--;//已经最大
        cout<<ans+1<<endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值