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);
    }
  • 相关阅读:
    Button 的CommandName 用法
    如何循序渐进向DotNet架构师发展
    用sqlserver进行分布式查询(链接服务器)(转)
    关于.resx
    OO设计原则总结
    为ASP.NET 2.0网站生成唯一程序集
    依赖倒置、控制反转和依赖注入辨析(转)
    通过http地址获取页面内容
    Sql同表去除重复
    动态启动WCF服务
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4991322.html
Copyright © 2011-2022 走看看