C - たくさんの数式 / Many Formulas

NX二次开发新建组件 NXOpen新建组件 阅读详情

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 and 9, 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

Copy
125

Sample Output 1

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.


Sample Input 2

Copy
9999999999

Sample Output 2

Copy
12656242944
题解:二进制思想。1代表有‘+‘,0代表没有。
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

long long toIntSum(string s)
{
    long long sum=0,tmp=0;
    for (int i=0;i<s.size();i++)
    {
        if(s[i]=='+')
        {
           sum+=tmp;
           tmp=0;
        }
        else
            tmp=tmp*10+s[i]-'0';

    }
    return sum+tmp;
}
int main ()
{
    string str;
    cin>>str;
    int len =str.size()-1,a[11]={0};//加号最多=串长-1;a[i]==0表示i处没有加号,a[i]==1表示i处有加号.
    long long sum=0;
    while(true)
    {
        string s;
        for (int i=0;i<len;i++)
        {
            a[i+1]+=a[i]/2;
            a[i]%=2;
        }
        if(a[len])
            break;
        for (int i=0;i<len;i++)//把加号和数字合成一个串
        {
            s+=str[i];
            if(a[i])
                s+="+";
        }
        s+=str[len];
        sum+=toIntSum(s);
        a[0]++;
    }
    cout<<sum;
    return 0;
}

CMake入门教程【基础篇】CMake+Visual Studio2022构建C++项目 CMake+Visual Studio2022搭建C++环境 阅读详情

相关推荐

【ATcode】たくさんの数式 / Many Formulas(思维)

题目链接 题目大意:现在给你一个数字,让你任意切割,然后就是切割出来的数字加起来,求得就是得到的和, 思路:看队友的思路后懂的,这个题目的话,就是把一个字符串,然后进行0 1的分割,利用二进制就可以实现所有的不重复的切割了,0的时候不切割,1的时候切割, 代码: #include<iostream> #include<algorithm> #include...

红点雷龙XL 392

从SFF-8087到SFF-8643:详解服务器硬盘背板连接线缆的演变与实战接线

本文深度解析了服务器硬盘背板连接技术从SFF-8087到SFF-8643的演进历程,重点介绍了SAS、SATA和U.2接口的技术特点与实战接线方案。通过对比不同连接器标准的物理特性和电气规范,提供了混合环境下的线缆选择策略和常见故障排查指南,帮助IT专业人员优化存储系统性能与稳定性。

weixin_30603633的博客 276

3.3——搜索 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 ...

VUno)UKGzseI 233

立创开源桌面激光雕刻机DIY全解析:从悬臂结构、Arduino主控到Marlin固件

本文详细解析了基于立创开源平台的桌面激光雕刻机DIY全过程。重点介绍了悬臂式机械结构的设计与优化,阐述了采用Arduino Mega 2560主控与RAMPS 1.4扩展板的经典控制方案,并深入讲解了Marlin固件的关键配置步骤,包括电机步数计算与激光功能启用,为创客和电子爱好者提供了一套完整的从硬件搭建到软件调试的实战指南。

weixin_42510201的博客 384

串行通信原理及实验仿真

1. 处理器与外部设备通信的两种方式: 并行通信和串行通信 并行通信是指数据的各个位用多条数据线同时进行传输 优点:传输速度快 缺点:占用引脚资源多 串行通信是将数据分成一位一位的形式在一条传输线上逐个传输 优点:通信线路简单,占用引脚资源少 缺点:传输速度慢 2. 串行通信的通信方式: 同步通信和异步通信 同步通信:带有时钟同步信号的数据传输;发送方和接收方在同一时钟的控制下,同步传输数据。 异步通信:不同时钟同步信号的数据传输。发送方和接收方使用各自的时钟控制数据的发送和接收过程。 3. 串行通

gemengxia的博客 4322

Many Formulas(暴力+有技巧)

题目链接:http://exam.upc.edu.cn/problem.php?id=6467题意:给你一个数字,在数字里任意加+号,问所有情况下,这个sum是多少我本来想了一种,后来发现这个题真的有意思。我有4种方法。第一种:自己写的,枚举    len从1~n。出现的个数和  +号的位置有关。#include&lt;bits/stdc++.h&gt; using namespace std; ...

Z_sea的博客 650

保姆级教程:Halcon 3D点云匹配与差异分析避坑指南(从采样到可视化)

本文提供了一份详细的Halcon 3D点云匹配与差异分析实战指南,涵盖从模型准备到可视化的全流程。重点解析了STL文件读取单位误区、点云采样密度优化、表面模型创建技巧以及差异分析的专业手法,帮助用户避开常见陷阱,提升工业检测效率与精度。

weixin_33728268的博客 402

C - Many Formulas(位运算)

C - Many Formulas(位运算)

ck的博客 177

2025.06.06【Ribo-seq】|riboWaltz:P-site定位与三碱基周期性分析流程

同学们,大家好!今天我们要学习的是riboWaltz——一款专为Ribo-seq(核糖体足迹测序)数据设计的R包,主要用于P-site定位优化和三碱基周期性分析。P-site的准确定位是Ribo-seq下游所有翻译组学分析的基础,riboWaltz为我们提供了系统、可视化、易用的解决方案。P-site定位优化:自动识别不同长度RPF的最佳P-site偏移量。三碱基周期性分析:可视化RPF在CDS、UTR等区域的分布,评估数据质量。多样本/多条件支持:可同时处理多个样本,便于批量分析和对比。

1793

紫光展锐面试——FPGA/IC设计面试面经案例总结

自我介绍;研究生的主要研究方向是什么?为什么想要应聘数字芯片相关的工作?简单介绍下数字IC设计流程。逻辑综合主要做什么?你有实际做过逻辑综合工作吗?你了解SS corner和FF corner吗?综合时应该使用哪个corner?综合时需要考虑hold吗?为什么?提高时钟频率对setup和hold有什么影响?为什么?hvt、rvt/svt、lvt有什么区别?c40、c50是指什么概念?有什么区别?你对EDA工具有过了解吗?

FPGA/MATLAB学习教程/源码/项目合作开发 1563

Atcoder 045C - Many Formulas(二进制枚举)

在给定的一段数字间添加+号构成等式,再求和。求所有可能的等式的和。每两个数字之间要么有+要么没有+,这可以对应于“1”和“0”。所以这个题就一个怎么放“1”的问题了。假设十个数1 2 3 4 5 6 7 8 9 0那么这十个数正好有9个空可以放“1”和“0”。(1,0分别代表有+号和无+)。那9个空的放法不就是29(即000000000~111111111),29才512。枚举每一种情况时间也不多。 #include<bits/stdc++.h> #define sc scanf typede.

qq_43022818的博客 412

066、AR 应用中虚拟物体漂移抖动?IMU 融合 + 光流追踪的视觉里程计优化方案

AR应用中虚拟物体漂移抖动优化方案 摘要:针对AR应用中虚拟物体漂移抖动问题,提出一种IMU融合与光流追踪的视觉里程计优化方案。关键点包括:1) 采用IMU预积分技术处理高频噪声,通过中值积分计算帧间相对运动约束;2) 使用金字塔LK光流追踪像素运动,通过中值偏差法剔除异常值;3) 构建10帧滑动窗口的紧耦合优化框架,将IMU预积分约束和光流重投影约束联合优化。实验表明,该方法有效解决了时间戳未对齐导致的"跳舞箭头"现象,在手机端实现稳定30fps的AR定位精度,漂移误差降低至厘米级。特别提醒:IMU与视觉

ai技术增长的博客 161

AtCoder Regular Contest 061--C - たくさんの数式 / Many Formulas(DFS)

C - たくさんの数式 / Many Formulas Time Limit: 2 sec / Memory Limit: 256 MB Score :300300points Problem Statement You are given a stringSSconsisting of digits between1and9, inclusive. You can inse...

lanshan1111的博客 372

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

C - たくさんの数式 / Many Formulas(位运算)

题目链接:https://atcoder.jp/contests/arc061/tasks/arc061_a Problem Statement You are given a stringSSconsisting of digits between1and9, inclusive. You can insert the letter+into some of the posit...

qq_40859951的博客 249

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

AtCoder Beginner Contest 045 C - たくさんの数式 / Many Formulas

C - たくさんの数式 / Many Formulas Time limit: 2sec /Memory limit: 256MB Score :300points Problem Statement You are given a stringSconsisting of digits between1and9, inclusive. You can in...

weixin_30375247的博客 156

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

AtCoder Beginner Contest 045 C - たくさんの数式 / Many Formulas

Time limit: 2sec /Memory limit: 256MB Score :300points Problem Statement You are given a stringSconsisting of digits between1and9, inclusive. You can insert the letter+into some of ...

weixin_30332241的博客 165

【AtCoder】ARC061

ARC061 C - たくさんの数式 / Many Formulas 这个其实\(10^5\)也能做。。 就是\(dp[i]\)表示到第i位的方案数,\(sum[i]\)表示延伸到第i位之前的所有方案的数字的和,\(pre[i]\)记录到第i位延伸已经结束了的数字的答案 转移是\(dp[i] = dp[i - 1] * 2\) \(sum[i] = sum[i - 1] * 10 + d...

weixin_30390075的博客 208

问题 : Many Formulas

这里我们可以考虑一下,这个题我们可以看作是设置断点的问题,断点将前后两个数分开,并求加和,所以我们只要判断从第一个数到倒数第二个数是否设置断点(最后一个数后面没数据,是否设置断点无意义了),即每一位0/1问题。这个题毫无疑问是可以用DFS做的。这里我们可以用二进制和位运算做。

xxcdlk的博客 444

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 n...

eazo的博客 333

Many Formulas

http://icpc.upc.edu.cn/problem.php?cid=1700&amp;pid=5 #include&lt;cstdio&gt; #include&lt;cstring&gt; using namespace std; char c[100]; long long l,i,j,ans,k; int main(){ scanf("%s",c); l=str...

Amber的博客 160

AtCoder Regular Contest 061

文章目录C - Many FormulasD - Snuke's ColoringE - Snuke's Subway TripF - Card Game for Three 传送门 C - Many Formulas Score : 300300300 points 爆搜 直接dfsdfsdfs爆搜即可 复杂度O(2n)O(2^n)O(2n) 代码 D - Snuke’s Coloring Score : 400400400 points 考虑有标记的3×33×33×3的格子很少,所以直接暴力跑这些格子

m0_51068403的博客 285

A - たくさんの数式 / Many Formulas AtCoder - 2067

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 letter...

PinesL 491

Atcoder 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. Yo

猿的进化 895

たくさんの数式 / Many Formulas(AtCoder-2067)

Problem Description 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 strin...

Alex_McAvoy的博客 563

6467: Many Formulas(二进制暴力)

6467: Many Formulas时间限制: 1 Sec  内存限制: 128 MB提交: 145  解决: 80[提交][状态][讨论版][命题人:admin]题目描述You are given a string S consisting of digits between 1 and 9, inclusive. You can insert the letter + into some o...

Sinhaeng_Hhjian 496
上一篇: 畅通工程经典例题(并查集+最小生成树+dij)hdu
下一篇: nyoj 入门级dp题目题解集
也道长
博客等级 码龄9年 11粉丝 52原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值