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 ...
随机推荐
- Java 浮点数精度控制
1.String.format(String format,Object… args) Java中用String.format()来控制输出精度, format参数用来设置精度格式, args参数代 ...
- Linux中通配符
通配符是由shell处理的, 它只会出现在 命令的“参数”里.当shell在“参数”中遇到了通配符时,shell会将其当作路径或文件名去在磁盘上搜寻可能的匹配:若符合要求的匹配存在,则进行代换(路径扩 ...
- HDU - 5187 zhx's contest(快速幂+快速乘法)
作为史上最强的刷子之一,zhx的老师让他给学弟(mei)们出n道题.zhx认为第i道题的难度就是i.他想要让这些题目排列起来很漂亮. zhx认为一个漂亮的序列{ai}下列两个条件均需满足. 1:a1. ...
- X86现代汇编·02
下面4这个寄存器只能用16位或3N位名称访问3N位寄存器 :ESI EDI EBP ESP 16位寄存器: SI DI BP SP 特殊用法:乘除指令默认用EAX默认使用ECX为循环计数器ESP用于寻 ...
- [爬坑日记] 安卓模拟器1903蓝屏 没开hyper-v
先说解决方案: 我在升级完1903之后短短几个小时蓝屏了两次 还是不同原因,不由得开始怀疑这个版本的稳定性,随后发现只有启动安卓模拟器的时候必然蓝屏(还有一次蓝屏实在安装驱动的时候) 经过百度得知需要 ...
- Logarithmic-Trigonometric积分系列(一)
\[\Large\displaystyle \int_{0}^{\frac{\pi }{2}}x^{2}\ln\left ( \sin x \right )\ln\left ( \cos x \rig ...
- ServletContext的使用
ServletContext: ServletContext表示Servlet应用程序.每个Web应用程序只有一个上下文.在将一个应用程序同时部署到多个容器的分布式环境中,每台Java虚拟机上的Web ...
- Atcoder Beginner Contest151D(迷宫问题求任意两点最短路径的最大值,BFS)
BFS可以求得最短路,DFS会找到从当前点到图中叶子结点的路径. #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using na ...
- 架构师必备技能指南:SaaS(软件即服务)架构设计
1.介绍 从计算机诞生开始,就伴随着计算机应用程序的演变.简短的回顾历史,我们可以清楚的看到应用程序发生的巨大变化.上世纪70年代中期,随着个人PC机的爆炸式增长以及程序员的崛起,让计算机的计算能力得 ...
- 【DRF版本控制】
目录 使用内置的URLPathVersioning类 使用自定义的版本控制类 "首先,我们开发的项目会有多个版本. 其次,我们的项目版本会随着更新越来越多,我们不可能因出了新版本就不维护旧版 ...