Many Formulas
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 and 9, inclusive.
输入
The input is given from Standard Input in the following format:
S
输出
Print the sum of the evaluated value over all possible formulas.
样例输入 Copy
125
样例输出 Copy
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.
#include <bits/stdc++.h>
using namespace std;
string s;
int cnt;
long long sum,t;
int main() {
//freopen("in", "r", stdin);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> s;
cnt = s.size();
for(int i = 0; i < (1 << (cnt - 1));i++){
t = s[0] - '0';
for(int j = 0; j < cnt; j++){
if(i & (1 << j) || j == cnt - 1){
sum += t;
t = 0;
if(j == cnt - 1) break;
}
t = t * 10 + (s[j + 1] - '0');
}
}
cout << sum << endl;
return 0;
}
Many Formulas的更多相关文章
- たくさんの数式 / Many Formulas AtCoder - 2067 (枚举二进制)
Problem Statement You are given a string S consisting of digits between 1 and 9, inclusive. You can ...
- AtCoder Beginner Contest 045 C - たくさんの数式 / Many Formulas
Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement You are given a string ...
- Codeforces 424 C. Magic Formulas
xor是满足交换律的,展开后发现仅仅要能高速求出 [1mod1....1modn],....,[nmod1...nmodn]的矩阵的xor即可了....然后找个规律 C. Magic Formulas ...
- CodeForce 424C Magic Formulas
这个题就是求出给的公式的结果. 仅仅要知道异或运算满足交换律跟结合律即可了.之后就是化简公式. #include<map> #include<string> #include& ...
- codeforce-424C. Magic Formulas(数学)
C. Magic Formulas time limit per test:2 seconds memory limit per test:256 megabytes input stan ...
- Experimental Educational Round: VolBIT Formulas Blitz
cf的一次数学场... 递推 C 题意:长度<=n的数只含有7或8的个数 分析:每一位都有2种可能,累加不同长度的方案数就是总方案数 组合 G 题意:将5个苹果和3个梨放进n个不同的盒子里的方案 ...
- Codeforces Round #242 (Div. 2) C. Magic Formulas
解题思路是: Q=q1^q2.......^qn = p1^p2......^pn^((1%1)^....(1%n))^((2%1)^......(2%n))^.... 故Q的求解过程分成两部分 第一 ...
- Codeforces Round #242 (Div. 2) C. Magic Formulas (位异或性质 找规律)
题目 比赛的时候找出规律了,但是找的有点慢了,写代码的时候出了问题,也没交对,还掉分了.... 还是先总结一下位移或的性质吧: 1. 交换律 a ^ b = b ^ a 2. 结合律 (a^b) ^ ...
- Npoi 导出Excel 下拉列表异常: String literals in formulas can't be bigger than 255 Chars ASCII
代码: public static void dropDownList(string[] datas, string filePath) { HSSFWorkbook workbook = new H ...
随机推荐
- 题解【CJOJ1070/UVA】嵌套矩形
P1070 - [Uva]嵌套矩形 Description 有 n 个矩形,每个矩形可以用两个整数 a, b 描述,表示它的长和宽.矩形 X(a, b) 可以嵌套在矩形 Y(c, d) 中当且仅当 a ...
- js Array 的所有方法
下面的这些方法会改变调用它们的对象自身的值: Array.prototype.copyWithin() 在数组内部,将一段元素序列拷贝到另一段元素序列上,覆盖原有的值. Array.prototyp ...
- Vue - 表单修饰符
.lazy 在默认情况下,v-model 在每次 input 事件触发后将输入框的值与数据进行同步 . 使用 lazy 修饰符,从而转变为使用 change 事件进行同步 <div id=&qu ...
- 能使Oracle索引失效的七大限制条件
Oracle 索引的目标是避免全表扫描,提高查询效率,但有些时候却适得其反. 例如一张表中有上百万条数据,对某个字段加了索引,但是查询时性能并没有什么提高,这可能是 oracle 索引失效造成的.or ...
- 题解【SP1043】 GSS1 - Can you answer these queries I
题目描述 You are given a sequence \(A_1, A_2, ..., A_n(|A_i|≤15007,1≤N≤50000)\). A query is defined as f ...
- python爬虫中图形验证码的处理
使用python爬虫自动登录时,遇到需要输入图形验证码的情况,一个比较简单的处理方法是使用打码平台识别验证码. 使用过两个打码平台,打码兔和若快,若快的价格更便宜,识别率相当.若快需要注册两个帐号:开 ...
- 解决MinGW运行时提示丢失libgmp-10.dll
如何解决刚安装的MinGW提示"丢失xxx.dll" 解决方案: 1.配置环境变量,出现这种问题的主要原因是因为没配置环境变量,网上的大多数解决方案也是基于这个的. 2.安装包损坏 ...
- Fiddler修改http请求响应简单实例
Fiddler是一个http调试代理,它能够记录并检查所有你的电脑和互联网之间的http通讯. 主要功能 设置断点,查看Fiddle说有的进出的数据(指cookie,html,js,css等文件,这些 ...
- 离线安装paramiko以及pysftp linux,windows
离线安装 paramiko python37 pip download -d ./dependency -r requirements.txt pip install --no-index --ign ...
- webstorm不能中文输入问题
版本:2018.1.4 原因:http://www.javatang.com/archives/2017/08/27/52101751.html 解决方案:https://www.cnblogs.co ...