AtCoder Beginner Contest 045 C - たくさんの数式 / Many Formulas
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
You are given a string S consisting of digits between 1
and 9
, inclusive. You can insert the letter +
into some of the positions (possibly none) between two letters in this string. Here, +
must not occur consecutively after insertion.
All strings that can be obtained in this way can be evaluated as formulas.
Evaluate all possible formulas, and print the sum of the results.
Constraints
- 1≤|S|≤10
- All letters in S are digits between
1
and9
, inclusive.
Input
The input is given from Standard Input in the following format:
S
Output
Print the sum of the evaluated value over all possible formulas.
Sample Input 1
125
Sample Output 1
176
There are 4 formulas that can be obtained: 125
, 1+25
, 12+5
and 1+2+5
. When each formula is evaluated,
- 125
- 1+25=26
- 12+5=17
- 1+2+5=8
Thus, the sum is 125+26+17+8=176.
Sample Input 2
9999999999
Sample Output 2
12656242944
题解:就是给一个数字字符串,然后在字符串中添加“ + ”把所有情况的 和 加和的结果;
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
bool cmp(int x,int y)
{
return x>y;
}
const int N=;
const int mod=1e9+;
char s[];
int pos[];
ll num(int l,int r)
{
ll ans=;
for(int i=l;i<=r;i++){
ans=ans*+s[i]-'';
}
return ans;
}
ll solve(int n)
{
int l=-,r=;
ll ans=;
pos[n]=;
for(int i=;i<=n;i++){
if(pos[i]==) r++;
else{
ans+=num(l+,i);
l=i;
}
}
return ans;
}
int main()
{
while(cin>>s){
int n=strlen(s);
ll ans=;
int R= (<<(n-))- ;
for(int i=;i<=R;i++){
mem(pos);
int tot=,temp=i;
while(temp){
pos[tot++]=temp%;
temp=temp/;
}
ans+=solve(n-);
}
printf("%lld\n",ans);
}
return ;
}
AtCoder Beginner Contest 045 C - たくさんの数式 / Many Formulas的更多相关文章
- AtCoder Beginner Contest 045 B - 3人でカードゲームイージー / Card Game for Three (ABC Edit)
Time limit : 2sec / Memory limit : 256MB Score : 200 points Problem Statement Alice, Bob and Charlie ...
- AtCoder Beginner Contest 154 题解
人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We ...
- AtCoder Beginner Contest 153 题解
目录 AtCoder Beginner Contest 153 题解 A - Serval vs Monster 题意 做法 程序 B - Common Raccoon vs Monster 题意 做 ...
- AtCoder Beginner Contest 177 题解
AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...
- 题解 AtCoder Beginner Contest 168
小兔的话 欢迎大家在评论区留言哦~ AtCoder Beginner Contest 168 A - ∴ (Therefore) B - ... (Triple Dots) C - : (Colon) ...
- AtCoder Beginner Contest 224
AtCoder Beginner Contest 224 A - Tires 思路分析: 判断最后一个字符即可. 代码如下: #include <bits/stdc++.h> using ...
- KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解
KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...
- AtCoder Beginner Contest 184 题解
AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...
- AtCoder Beginner Contest 173 题解
AtCoder Beginner Contest 173 题解 目录 AtCoder Beginner Contest 173 题解 A - Payment B - Judge Status Summ ...
随机推荐
- 【C++问题整理】
一.static 1.作用: 静态变量/函数:在整个文件内可见,不会被其他文件所用:静态变量:会被自动初始化为0: 类中的静态变量:类的成员,类对象公用 类中的静态函数:只能访问静态变量 2 ...
- root_objectlist, root_object, container_objectlist, container_object 之间的关系。
- sap 调试工具,修改变量值
1: 点击修改,输入变量值,按enter键.
- Jquery书写AJAX动态向页面form传数据,清空之前的数据
三种方式: 直接代码: 1.$("#mytable tr:gt(0)").remove(); 2.$("#mytable tr:not(:first)").em ...
- 抛异常 throw的注意事项
子类覆盖父类只能抛出父类的异常或者子类或者子集注意:如果父类的方法没有抛异常,那么子类覆盖时绝对不能抛. 子类继承父类时,方法抛异常,要么抛父类,要么抛父类下的子类,不能抛父类平级或以上的异常 原因是 ...
- 天气服务API文档 第1版
HTTP接口设计文档 此文档为开发HTTP接口的设计文档,目前用于提供天气查询的相关接口. 测试的时候使用 URL=http://www.dennisthink.com/test/api/weathe ...
- ERROR [main] zookeeper.RecoverableZooKeeper: ZooKeeper create failed after 4 attempts
ERROR [main] zookeeper.RecoverableZooKeeper: ZooKeeper create failed after 4 attempts ERROR [main] m ...
- 删除docker下的镜像
先显示一下docker中的镜像 删除镜像 先停止这个容器 删除容器 再删除镜像就可以啦!
- 移动端--touch事件与点透问题
也来说说touch事件与点击穿透问题: http://blog.csdn.net/alex8046/article/details/52299785
- Adobe Flash Builder 调试器无法连接,无法进行调试,构建停止在57%
参考:https://blog.csdn.net/wuboyaogun1/article/details/9105373 谷歌浏览器下载Flash debugger :Download the Win ...