C++ 小玉在游泳

文章目录


一、题目描述

小玉在游泳

题目描述

小玉开心的在游泳,可是她很快难过的发现,自己的力气不够,游泳好累哦。已知小玉第一步能游 2 2 2 米,可是随着越来越累,力气越来越小,她接下来的每一步都只能游出上一步距离的 98 % 98\% 98%。现在小玉想知道,如果要游到距离 s s s 米的地方,她需要游多少步呢。请你编程解决这个问题。

输入格式

输入一个实数 s s s(单位:米),表示要游的目标距离。

输出格式

输出一个整数,表示小玉一共需要游多少步。

样例 #1

样例输入 #1

复制代码
4.3

样例输出 #1

复制代码
3

提示

数据保证, 0 ≤ s < 100 0 \leq s < 100 0≤s<100,且 s s s 小数点后最多只有一位。


二、参考代码

cpp 复制代码
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;


int main(void)
{
	double s = 2, sum = 2;
	double dis = 0;
	cin >> dis;
	int days = 1;
	while (1)
	{
		if (sum >= dis)
		{
			break;
		}
		else
		{
			days++;
			s *= 0.98;
			sum += s;
			
		}
	}
	cout << days;
}

相关推荐
Hello_WOAIAI8 分钟前
4.2 python多线程编程:threading 模块深度解析
开发语言·python
2501_9411119917 分钟前
C++中的装饰器模式变体
开发语言·c++·算法
树下水月39 分钟前
python 连接hive2 数据库
开发语言·数据库·python
Tom4i41 分钟前
Kotlin 中的 inline 和 reified 关键字
android·开发语言·kotlin
怕什么真理无穷41 分钟前
C++_面试15_零拷贝
c++·面试·职场和发展
凄戚44 分钟前
bash和命令
开发语言·chrome·bash
Evan芙1 小时前
Bash 变量命名规则与类型使用
linux·运维·开发语言·chrome·bash
Espresso Macchiato1 小时前
Leetcode 3748. Count Stable Subarrays
算法·leetcode·职场和发展·leetcode hard·leetcode 3748·leetcode周赛476·区间求和
AA陈超1 小时前
ASC学习笔记0007:用于与GameplayAbilities系统交互的核心ActorComponent
c++·笔记·学习·ue5·虚幻引擎