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 = ;
long long solve(int l,int r)
{
if(l!=r&&s[l]=='')return -;
long long res = ;
for(int i=l;i<=r;i++)
{
res = res * + (s[i]-'');
if(res>)
return -;
}
return res;
}
int main()
{
cin>>s;
int flag = ;
for(int i=;i<s.size();i++)
{
for(int j=i+;j<s.size();j++)
{
long long sum1 = solve(,i-);
long long sum2 = solve(i,j-);
long long sum3 = solve(j,s.size()-);
if(sum1==-||sum2==-||sum3==-)
continue;
ans = max(ans,sum1+sum2+sum3);
flag = ;
}
}
if(flag==)
return puts("-1");
printf("%d\n",ans);
}
Codeforces Round #115 A. Robot Bicorn Attack 暴力的更多相关文章
- A - Robot Bicorn Attack
Description Vasya plays Robot Bicorn Attack. The game consists of three rounds. For each one a non-n ...
- Codeforces Round #307 (Div. 2) B. ZgukistringZ 暴力
B. ZgukistringZ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/probl ...
- Codeforces Round #115 B. Plane of Tanks: Pro 水题
B. Plane of Tanks: Pro Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/17 ...
- Codeforces Round #328 (Div. 2) A. PawnChess 暴力
A. PawnChess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/ ...
- Codeforces Round #404 (Div. 2)(A.水,暴力,B,排序,贪心)
A. Anton and Polyhedrons time limit per test:2 seconds memory limit per test:256 megabytes input:sta ...
- Codeforces Round #369 (Div. 2) A B 暴力 模拟
A. Bus to Udayland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Educational Codeforces Round 5 B. Dinner with Emma 暴力
B. Dinner with Emma 题目连接: http://www.codeforces.com/contest/616/problem/A Description Jack decides t ...
- Codeforces Round #188 (Div. 1) B. Ants 暴力
B. Ants Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/317/problem/B Des ...
- Codeforces Round #329 (Div. 2) A. 2Char 暴力
A. 2Char Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/problem/A De ...
随机推荐
- 【转】iOS学习之Autolayout(代码添加约束) -- 不错不错
原文网址:http://www.cnblogs.com/HypeCheng/articles/4192154.html DECEMBER 07, 2013 学习资料 文章 Beginning Auto ...
- 【转】iPhone屏幕尺寸、分辨率及适配
原文网址:http://blog.csdn.net/phunxm/article/details/42174937 1.iPhone尺寸规格 设备 iPhone 宽 Width 高 Height 对角 ...
- 【转】cocos2d-x 3.2 Fast TileMap
概述 在游戏中常常会有丰富的背景元素,如果直接使用大的背景图实现,这会造成资源浪费.TileMap就是为了解决这问题而产生的.Cocos2d-x支持使用Tile地图编辑器创建的TMX格式的地图. Co ...
- 自己动手写路由器之ioctl获取网络接口信息
最近打算写一个简单路由器,里面有用到ioctl获取网络接口信息,那就先把这部分单独拿出来说一说吧! ioctl这个函数,可以用来对特殊文件的基础设备参数进行操作,它们可以完成与打开文件描述符相关联的控 ...
- linux命令——磁盘管理pwd
Linux中用 pwd 命令来查看”当前工作目录“的完整路径(绝对路径). 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录.在不太确定当前位置时,就会使用pwd来判定当前目录在文件系统内的 ...
- LINQ to SQL语句之Join和Order By
Join操作 适用场景:在我们表关系中有一对一关系,一对多关系,多对多关系等.对各个表之间的关系,就用这些实现对多个表的操作. 说明:在Join操作中,分别为Join(Join查询), SelectM ...
- C++ 编程输入输出语句
C++ 的标准输入.输出就是我们已经使用的包含头文件iostream,他不但提供了I/O的库函数,也提供了使用该库的流模式,从cin>> 流入 和cout<<流出到设备就是一 ...
- wuzhicms水印的设置
- 机器学习中的数学(1)-回归(regression)、梯度下降(gradient descent)
版权声明: 本文由LeftNotEasy所有,发布于http://leftnoteasy.cnblogs.com.如果转载,请注明出处,在未经作者同意下将本文用于商业用途,将追究其法律责任. 前言: ...
- JAVA WEB SQLHelper类的封装
在这次做项目中,我对自己最满意的就是封装了一下SQLHelper类,我对自己感到骄傲主要是 我是初学者,我刚开始不知道可以这样做,我只是想着试着去这样做了,结果真的可以,所以我 在我的模块就自己封装了 ...