当前位置:网站首页>给定一个正整数N,将其表示为数字1,3,7,15相加的形式输出。请编码找出使上述数字出现的总次数最少(每个数字可以重复使用)的组合。
给定一个正整数N,将其表示为数字1,3,7,15相加的形式输出。请编码找出使上述数字出现的总次数最少(每个数字可以重复使用)的组合。
2022-07-20 05:32:00 【-借我杀死庸碌的情怀-】
给定一个正整数N,将其表示为数字1,3,7,15相加的形式输出。请编码找出使上述数字出现的总次数最少(每个数字可以重复使用)的组合。
- 输入说明:一个正整数N(N<=10000)。
- 输出说明:正整数N由1,3,7,15组成的加法表达式,左侧是N,之后是’=‘号,’='右侧是数字加和的形式,要求非递增排列。
- 举例:
输入:17
输出:17=15+1+1
#include <iostream>
using namespace std;
int main()
{
int N;
cin >> N;
int a = N / 15;
int b = (N - a * 15) / 7;
int c = (N - a * 15 - b * 7) / 3;
int d = N - a * 15 - b * 7 - c * 3;
string str;
while (a > 0)
{
str += "15+";
a -= 1;
}
while (b > 0)
{
str += "7+";
b -= 1;
}
while (c > 0)
{
str += "3+";
c -= 1;
}
while (d > 0)
{
str += "1+";
d -= 1;
}
str.erase(str.length() - 1);
cout << N << "=" << str;
return 0;
}
演示截图:
注:
边栏推荐
- Basic architecture of data warehouse -- layered functions
- 辨析Iteration、epoch及batchsize之间的关系
- Hyperledger Fabric 超级账本 CA集群搭建使用
- Paper study -- resource allocation for multi user downlink miso OFDMA urllc systems
- (三)PyTorch深度学习:反向传播梯度下降
- 【深度学习】运用mnist数据集实例化一个简单的卷积神经网络
- TensorFlow v1 入门教程
- (8) Pytorch deep learning: convolutional neural network (basic) -- change (VII) fully connected neural network into convolutional neural network
- (10) Pytorch deep learning: convolutional neural network (simple residual convolutional neural network)
- Paper learning -- resource allocation in EE urllc in relay system
猜你喜欢
Paper learning -- resource allocation in EE urllc in relay system
(2) Pytorch deep learning: gradient descent
Mysql 主从复制 docker集群搭建
论文学习--Resource allocation for multi-user downlink MISO OFDMA-URLLC systems
Select all on the current page of Ali vector Gallery
EndNote X9导入论文投稿的期刊参考文献格式
理解原始Gan Loss 和 Hinge Gan Loss
2D目标检测综述之神经网络篇
电脑端微信有很多垃圾可以清理
Five basic data types of redis (super detailed)
随机推荐
Opencv系列教程(一):Opencv读取指定文件夹图片、视频,调用摄像头
(5) Pyqt5 series tutorials: use pychart to design the internal logic of pyqt5 in the serial port assistant parameter options (II)
qlineargradient中坐标的含义
JS event flow (capture phase, target phase, bubble phase) cancels the default bubble behavior of the browser
(8) Pytorch deep learning: convolutional neural network (basic) -- change (VII) fully connected neural network into convolutional neural network
论文学习---Resource allocation in EE URLLC in Relay System
玩转CANN目标检测与识别一站式方案【介绍篇】
Flink datastream API (XIV) Flink output to MySQL (JDBC)
二分图
Li Hongyi 2020 machine learning -- P11 logistic progression
Paper learning -- resource allocation in EE urllc in relay system
【2022年第一期 CANN训练营进阶班应用课】附加题——媒体数据处理+模型推理
SQL事务
(八)PyTorch深度学习:卷积神经网络(基础)---将(七)全连接神经网络改成卷积神经网络
MIMO-OFDM无线通信技术及MATLAB实现读书笔记-衰落信道&室内信道(1)
【2022年第一期 CANN训练营进阶班模型课】第一次大作业和附加内容
The insertion order of single chain storage structure
Realization of data warehouse technology
理解Seperable Convolution
Statistical information collection of dream