当前位置:网站首页>刷题-洛谷-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;
}
边栏推荐
- Docekr learning - MySQL 8 master-slave replication setup deployment
- Convolutional neural network model -- vgg-16 network structure and code implementation
- hcip第八天实验
- 我的创作纪念日
- 二叉树基本知识
- My creation anniversary
- Discussion on principle and application technology of MLIR
- 剑指offer专项突击版第10天
- 0720RHCSA
- [figure attack and Defense] backdoor attacks to graph neural networks (sacmat '21)
猜你喜欢

运动豪华还是安全豪华?亚洲龙与沃尔沃S60该入手哪款?

Redis可视化工具RDM安装包分享

0716RHCSA

嵌入式代码如何进行重构?

错误: 找不到或无法加载主类 xxxx
![[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 final chapter] alphacode: competition level code generation with alphacode (deepmind)](/img/05/86eed30a7c063beace400a005e4a4c.png)
[ai4code final chapter] alphacode: competition level code generation with alphacode (deepmind)

Brpc source code analysis (III) -- the mechanism of requesting other servers and writing data to sockets

【GCN】《Adaptive Propagation Graph Convolutional Network》(TNNLS 2020)

In order to improve efficiency, there are various problems when using parallelstream
随机推荐
Pycharm cannot input Chinese solution
Numpy quick start
Mlx90640 infrared thermal imager temperature sensor module development notes (V)
Mutex lock, spin lock, read-write lock... Clarify their differences and applications
Hcip day 9 notes
Convolutional neural network model -- googlenet network structure and code implementation
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
Based on Baiwen imx6ull_ Pro development board transplants LCD multi touch driver (gt911)
2022年下半年软考初级程序员备考
stable_ Baselines quick start
6W+字记录实验全过程 | 探索Alluxio经济化数据存储策略
【服务器数据恢复】HP EVA服务器存储RAID信息断电丢失的数据恢复
安装mujoco报错:distutils.errors.DistutilsExecError: command ‘gcc‘ failed with exit status 1
并发编程之并发工具集
Django 2 ----- 数据库与Admin
Based on Baiwen imx6ull_ Ap3216 experiment driven by Pro development board
Online Learning and Pricing with Reusable Resources: Linear Bandits with Sub-Exponential Rewards: Li
2022全球开发者中,你的收入排多少?
0713RHCSA
ThreadLocal&Fork/Join