当前位置:网站首页>刷题-洛谷-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;
}
边栏推荐
- stable_baselines快速入门
- 程序员成长第二十七篇:如何评估需求优先级?
- Docekr learning - MySQL 8 master-slave replication setup deployment
- Excel import and export source code analysis
- Brpc source code analysis (III) -- the mechanism of requesting other servers and writing data to sockets
- Leetcode 113. path sum II
- Numpy快速入门
- 【GCN-RS】Region or Global? A Principle for Negative Sampling in Graph-based Recommendation (TKDE‘22)
- stable_ Baselines quick start
- 为提高效率使用ParallelStream竟出现各种问题
猜你喜欢

Docekr learning - MySQL 8 master-slave replication setup deployment

面试官问我:Mysql的存储引擎你了解多少?

vim基础操作汇总

【CTR】《Towards Universal Sequence Representation Learning for Recommender Systems》 (KDD‘22)

Generate SQL script file by initializing the latest warehousing time of vehicle attributes

IM系统-消息流化一些常见问题

Redis visualizer RDM installation package sharing

R language GLM generalized linear model: logistic regression, Poisson regression fitting mouse clinical trial data (dose and response) examples and self-test questions

In order to improve efficiency, there are various problems when using parallelstream

Convolutional neural network model -- googlenet network structure and code implementation
随机推荐
Redis visualizer RDM installation package sharing
卷积神经网络模型之——LeNet网络结构与代码实现
Mujoco+spinningup for intensive learning training quick start
Hcip day 9 notes
ThreadLocal&Fork/Join
一味地做大元宇宙的规模,已经背离了元宇宙本该有的发展逻辑
Mlx90640 infrared thermal imager temperature sensor module development notes (V)
【视频】马尔可夫链原理可视化解释与R语言区制转换MRS实例|数据分享
Gym安装、调用以及注册
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
Machine learning strong foundation program 0-4: popular understanding of Occam razor and no free lunch theorem
Shell common script: get the IP address of the network card
QingChuang technology joined dragon lizard community to build a new ecosystem of intelligent operation and maintenance platform
How to solve the problem of taking up too much space when recording and editing videos?
Uncaught SyntaxError: Octal literals are not allowed in strict mode.
stable_ Baselines quick start
How to refactor embedded code?
Online Learning and Pricing with Reusable Resources: Linear Bandits with Sub-Exponential Rewards: Li
面试官问我:Mysql的存储引擎你了解多少?
0716RHCSA