当前位置:网站首页>刷题-洛谷-P1150 Peter的烟
刷题-洛谷-P1150 Peter的烟
2022-07-25 13:32:00 【宋向上_UP】
P1150 Peter的烟-C语言
1、题目

2、解题过程
(1)第一次 while循环中的条件不足,应为surplus >=k
结果:
代码:
//洛谷 P1150 Peter的烟
#include <stdio.h>
int main() {
int n;//Peter原始的烟数目
int k;//k(k>1)个烟蒂可以换一个新烟
int sum=0;//Peter能够吸到的烟数目
int exchange;//可以交换的数目
int surplus;//剩余还没交换的烟数目
//int i = 1;
scanf_s("%d %d", &n, &k);
sum = n;//原始烟数目
exchange = n / k;//可以交换的烟数目
sum = sum + exchange;
surplus = n - exchange * k+ exchange;//剩余的烟数目
while (surplus > k) {
exchange = surplus / k;//交换的烟数目
sum = sum + exchange;
surplus = surplus - exchange * k + exchange;
//printf("执行了第%d次\n", i);
//i++;
}
printf("%d", sum);
return 0;
}
(2)第二次
结果:
代码:
//洛谷 P1150 Peter的烟
#include <stdio.h>
int main() {
int n;//Peter原始的烟数目
int k;//k(k>1)个烟蒂可以换一个新烟
int sum=0;//Peter能够吸到的烟数目
int exchange;//可以交换的数目
int surplus;//剩余还没交换的烟数目
//int i = 1;
scanf("%d %d", &n, &k);
sum = n;//原始烟数目
exchange = n / k;//可以交换的烟数目
sum = sum + exchange;
surplus = n - exchange * k+ exchange;//剩余的烟数目
while (surplus >= k) {
exchange = surplus / k;//交换的烟数目
sum = sum + exchange;
surplus = surplus - exchange * k + exchange;
//printf("执行了第%d次\n", i);
//i++;
}
printf("%d", sum);
return 0;
}
边栏推荐
- 卷积神经网络模型之——AlexNet网络结构与代码实现
- Excel添加按键运行宏
- Canvas判断内容为空
- Shell common script: judge whether the file of the remote host exists
- 2022全球开发者中,你的收入排多少?
- Mu Changchun, data Research Institute of the central bank: controllable anonymity of digital RMB is an objective need to safeguard public interests and financial security
- 【AI4Code】CodeX:《Evaluating Large Language Models Trained on Code》(OpenAI)
- Convolutional neural network model -- lenet network structure and code implementation
- Error: cannot find or load main class XXXX
- Redis visualizer RDM installation package sharing
猜你喜欢
[email protected](using password:YES)"/>全网最简单解决方式1045-Access denied for user [email protected](using password:YES)

G027-OP-INS-RHEL-04 RedHat OpenStack 创建自定义的QCOW2格式镜像
![[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing](/img/6e/9e0abf8db5ec93080033bd89605ac2.jpg)
[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing

领域驱动模型设计与微服务架构落地-模型设计

【AI4Code】《Pythia: AI-assisted Code Completion System》(KDD 2019)

Excel录制宏

QGIS加载在线地图:高德、天地图等

Jupyter Notebook介绍
![[figure attack and Defense] backdoor attacks to graph neural networks (sacmat '21)](/img/d2/6be99fd194c66e4f60af38c6e52c93.png)
[figure attack and Defense] backdoor attacks to graph neural networks (sacmat '21)

【AI4Code】《Unified Pre-training for Program Understanding and Generation》 NAACL 2021
随机推荐
若依如何实现用户免密登录配置方法?
Shell common script: get the IP address of the network card
【AI4Code】CodeX:《Evaluating Large Language Models Trained on Code》(OpenAI)
Leetcode 113. path sum II
In order to improve efficiency, there are various problems when using parallelstream
2022全球开发者中,你的收入排多少?
基于百问网IMX6ULL_PRO开发板移植LCD多点触摸驱动(GT911)
6.27 uniapp project history
hcip第七天笔记
0710RHCSA
Online Learning and Pricing with Reusable Resources: Linear Bandits with Sub-Exponential Rewards: Li
TCP的拥塞控制
央行数研所穆长春:数字人民币可控匿名是维护公众利益和金融安全的客观需要
VIM basic operation summary
uniapp处理后台传输图片
Docekr learning - MySQL 8 master-slave replication setup deployment
JS Array indexOf includes sort() 冒号排序 快速排序 去重和随机样本 random
Hcip day 10 notes
Detailed explanation of the training and prediction process of deep learning [taking lenet model and cifar10 data set as examples]
Excel add key run macro