zoukankan      html  css  js  c++  java
  • 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
    ",ans);
    }
  • 相关阅读:
    HDU 2089 不要62 (数位DP)
    数位DP总结
    怒刷DP之 HDU 1160
    将时间转为几小时前,几周前,几天前等
    link与import的区别
    什么是虚拟DOM?为啥虚拟DOM可以提升性能?
    前端面试问题2
    【转载】什么是闭包? 闭包的优缺点 闭包的应用场景
    小程序发布审核不通过
    前端面试常问 问题总结
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4991322.html
Copyright © 2011-2022 走看看