当前位置:网站首页>Brush questions - Luogu -p1150 Peter's smoke
Brush questions - Luogu -p1150 Peter's smoke
2022-07-25 13:46:00 【Song Xiangshang_ UP】
P1150 Peter The smoke of -C Language
1、 subject

2、 The problem solving process
(1) for the first time while Insufficient conditions in the loop , Should be surplus >=k
result :
Code :
// Luogu P1150 Peter The smoke of
#include <stdio.h>
int main() {
int n;//Peter The original number of cigarettes
int k;//k(k>1) A cigarette butt can be exchanged for a new cigarette
int sum=0;//Peter The number of cigarettes you can smoke
int exchange;// The number that can be exchanged
int surplus;// The number of cigarettes remaining that have not been exchanged
//int i = 1;
scanf_s("%d %d", &n, &k);
sum = n;// Original smoke number
exchange = n / k;// The number of cigarettes that can be exchanged
sum = sum + exchange;
surplus = n - exchange * k+ exchange;// Number of cigarettes remaining
while (surplus > k) {
exchange = surplus / k;// Number of cigarettes exchanged
sum = sum + exchange;
surplus = surplus - exchange * k + exchange;
//printf(" Implemented section %d Time \n", i);
//i++;
}
printf("%d", sum);
return 0;
}
(2) The second time
result :
Code :
// Luogu P1150 Peter The smoke of
#include <stdio.h>
int main() {
int n;//Peter The original number of cigarettes
int k;//k(k>1) A cigarette butt can be exchanged for a new cigarette
int sum=0;//Peter The number of cigarettes you can smoke
int exchange;// The number that can be exchanged
int surplus;// The number of cigarettes remaining that have not been exchanged
//int i = 1;
scanf("%d %d", &n, &k);
sum = n;// Original smoke number
exchange = n / k;// The number of cigarettes that can be exchanged
sum = sum + exchange;
surplus = n - exchange * k+ exchange;// Number of cigarettes remaining
while (surplus >= k) {
exchange = surplus / k;// Number of cigarettes exchanged
sum = sum + exchange;
surplus = surplus - exchange * k + exchange;
//printf(" Implemented section %d Time \n", i);
//i++;
}
printf("%d", sum);
return 0;
}
边栏推荐
- 并发编程之并发工具集
- Framework package merge script
- Based on Baiwen imx6ull_ Ap3216 experiment driven by Pro development board
- stable_baselines快速入门
- Arrays常用方法
- mujoco+spinningup进行强化学习训练快速入门
- VIM basic operation summary
- mujoco_py中文文档
- Leetcode 113. 路径总和 II
- 【Platform IO编译Hifive1-revB】*** [.pio\build\hifive1-revb\src\setupGPIO.o] Error 1的解决办法
猜你喜欢

刷题-洛谷-P1046 陶陶摘苹果

移动端网站,独立APP,网站排名策略有哪些?

Excel record macro

2022全球开发者中,你的收入排多少?

2022年下半年软考信息安全工程师如何备考?

Basic knowledge of binary tree

Redux usage and analysis

飞盘局有多快乐?2022年轻人新潮运动报告

Install mujoco and report an error: distutils.errors DistutilsExecError: command ‘gcc‘ failed with exit status 1

Workplace "digital people" don't eat or sleep 007 work system, can you "roll" them?
随机推荐
Gym installation, invocation and registration
Sports luxury or safety luxury? Which type of Asian Dragon and Volvo S60 should we start with?
Leetcode 113. 路径总和 II
Introduction to jupyter notebook
@wrap 装饰器
hcip第九天笔记
I2C can also be powered on by bus!
IM系统-消息流化一些常见问题
说说对hashcode和equals方法的理解?
pytest.mark.parametrize及mock使用
刷题-洛谷-P1151 子数整数
Install mujoco and report an error: distutils.errors DistutilsExecError: command ‘gcc‘ failed with exit status 1
【力扣】1030.距离顺序排列矩阵单元格
The whole process of 6w+ word recording experiment | explore the economical data storage strategy of alluxio
@Classmethod decorator
Business visualization - make your flowchart'run'(3. Branch selection & cross language distributed operation node)
hcip第八天实验
sieve of eratosthenes
埃拉托斯特尼筛法
QGIS加载在线地图:高德、天地图等