Codeforces Round #115 A. Robot Bicorn Attack 暴力

A. Robot Bicorn Attack

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/175/problem/A

Description

Vasya plays Robot Bicorn Attack.

The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played three rounds and wrote obtained points one by one (without leading zeros) into the string s. Vasya decided to brag about his achievement to the friends. However, he has forgotten how many points he got for each round. The only thing he remembers is the string s.

Help Vasya to find out what is the maximum amount of points he could get. Take into account that Vasya played Robot Bicorn Attack for the first time, so he could not get more than 1000000 (106) points for one round.

Input

The only line of input contains non-empty string s obtained by Vasya. The string consists of digits only. The string length does not exceed 30 characters.

Output

Print the only number — the maximum amount of points Vasya could get. If Vasya is wrong and the string could not be obtained according to the rules then output number -1.

Sample Input

1234

Sample Output

37

HINT

 

题意

给你一个字符串,要求使得字符串分为3节,并且每节都不能带首位0

并且每一节的数字都不能超过1e6

问你这三节的和最大可能为多少

题解:

暴力咯,数据范围只有30~

不过这道题如果数据范围出到1e5的话,是一道非常好玩的题目哦~

代码:

#include<iostream>
#include<stdio.h>
using namespace std;

string s;
long long ans = 0;
long long solve(int l,int r)
{
    if(l!=r&&s[l]=='0')return -1;
    long long res = 0;
    for(int i=l;i<=r;i++)
    {
        res = res * 10 + (s[i]-'0');
        if(res>1000000)
            return -1;
    }
    return res;
}
int main()
{
    cin>>s;
    int flag = 0;
    for(int i=1;i<s.size();i++)
    {
        for(int j=i+1;j<s.size();j++)
        {
            long long sum1 = solve(0,i-1);
            long long sum2 = solve(i,j-1);
            long long sum3 = solve(j,s.size()-1);
            if(sum1==-1||sum2==-1||sum3==-1)
                continue;
            ans = max(ans,sum1+sum2+sum3);
            flag = 1;
        }
    }
    if(flag==0)
        return puts("-1");
    printf("%d\n",ans);
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值