当前位置:网站首页>刷题-洛谷-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;
}
边栏推荐
- Shell common script: check whether a domain name and IP address are connected
- Azure Devops(十四) 使用Azure的私有Nuget仓库
- 0719RHCSA
- Cv2.resize function reports an error: error: (-215:assertion failed) func= 0 in function ‘cv::hal::resize‘
- Design and principle of thread pool
- ThreadLocal&Fork/Join
- Peripheral system calls SAP's webapi interface
- Numpy quick start
- 嵌入式代码如何进行重构?
- 6W+字记录实验全过程 | 探索Alluxio经济化数据存储策略
猜你喜欢

Docker learning - redis cluster -3 master and 3 slave - capacity expansion - capacity reduction building

ESP32-C3 基于Arduino框架下Blinker点灯控制10路开关或继电器组

Date and time function of MySQL function summary

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

Introduction to jupyter notebook

Basic knowledge of binary tree

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

Excel add key run macro

Esp32-c3 is based on blinker lighting control 10 way switch or relay group under Arduino framework

Brpc source code analysis (III) -- the mechanism of requesting other servers and writing data to sockets
随机推荐
Any time, any place, super detective, seriously handle the case!
R language GLM generalized linear model: logistic regression, Poisson regression fitting mouse clinical trial data (dose and response) examples and self-test questions
Blocking queue for concurrent programming
int数组获取重复数据
Excel录制宏
0719RHCSA
[figure attack and Defense] backdoor attacks to graph neural networks (sacmat '21)
ESP32-C3 基于Arduino框架下Blinker点灯控制10路开关或继电器组
0713RHCSA
Pycharm cannot input Chinese solution
Generate SQL script file by initializing the latest warehousing time of vehicle attributes
0715RHCSA
【视频】马尔可夫链原理可视化解释与R语言区制转换MRS实例|数据分享
Hcip day 8 notes
Numpy快速入门
arm架构移植alsa-lib和alsa-utils一路畅通
【GCN-CTR】DC-GNN: Decoupled GNN for Improving and Accelerating Large-Scale E-commerce Retrieval WWW22
The interviewer asked me: how much do you know about MySQL's storage engine?
stable_baselines快速入门
0716RHCSA