The Snail ——蜗牛逃出井

『杭电1302』The Snail Problem Description A snail is at the bottom of a 6-foot well and wants to climb to the top. The snail can climb 3 feet while the sun is up, but slides down 1 foot at night while sleeping. The snail has a fatigue factor of 10%, which means that on each s 阅读详情


  The Snail 

A snail is at the bottom of a 6-foot well and wants to climb to the top. The snail can climb 3 feet while the sun is up, but slides down 1 foot at night while sleeping. The snail has a fatigue factor of 10%, which means that on each successive day the snail climbs 10% $\times$ 3 = 0.3 feet less than it did the previous day. (The distance lost to fatigue is always 10% of the first day's climbing distance.) On what day does the snail leave the well, i.e., what is the first day during which the snail's height exceeds 6 feet? (A day consists of a period of sunlight followed by a period of darkness.) As you can see from the following table, the snail leaves the well during the third day.

DayInitial HeightDistance ClimbedHeight After ClimbingHeight After Sliding
10'3'3'2'
22'2.7'4.7'3.7'
33.7'2.4'6.1'-

Your job is to solve this problem in general. Depending on the parameters of the problem, the snail will eventually either leave the well or slide back to the bottom of the well. (In other words, the snail's height will exceed the height of the well or become negative.) You must find out which happens first and on what day.

Input 

The input file contains one or more test cases, each on a line by itself. Each line contains four integers  H ,  U ,  D , and  F , separated by a single space. If  H  = 0 it signals the end of the input; otherwise, all four numbers will be between 1 and 100, inclusive.  H  is the height of the well in feet,  U  is the distance in feet that the snail can climb during the day,  D  is the distance in feet that the snail slides down during the night, and  F  is the fatigue factor expressed as a percentage. The snail  never  climbs a negative distance. If the fatigue factor drops the snail's climbing distance below zero, the snail does not climb at all that day. Regardless of how far the snail climbed, it always slides  D feet at night.

Output 


For each test case, output a line indicating whether the snail succeeded (left the well) or failed (slid back to the bottom) and on what day. Format the output exactly as shown in the example.

Sample Input 

6 3 1 10
10 2 1 50
50 5 3 14
50 6 4 1
50 6 3 1
1 1 1 1
0 0 0 0

Sample Output 

success on day 3
failure on day 4
failure on day 7
failure on day 68
success on day 20
failure on day 2


题意:一只小蜗牛想爬出井,已知井的深度为H,蜗牛白天能爬U米,晚上休息下滑D米,蜗牛的疲劳因子为F(即蜗牛每天往上爬的距离总比前一天少F%*U米),问蜗牛能否爬上井口,如果能,问第几天能够爬上井口,如果不能,问第几天失败。注意,这里的失败是指蜗牛“爬”到了井底。。。。。。

题解:一个循环模拟的过程,记录总路程和前一天走的距离(用于计算当天走的距离),如果总路程大于井的深度,则在这一天蜗牛成功走出井口,如果总路程小于0,则代表蜗牛滑到了井底,在这一天失败了。注意要分开判断,白天蜗牛再往上爬,判断是否达到井口,晚上蜗牛下滑,判断是否滑到了井底。

特别注意:如果某一天走的距离小于0了,就不要再让总数加上这个负数了,因为如果加上的话,后面还会减去晚上下降的,所以相当于多减了,会造成失败天数产生误差。


#include <stdio.h>
#include <string.h>
#include <math.h>

int main()
{
    double H,U,D,F;
    double s,sum;
    int i;
    while(scanf("%lf%lf%lf%lf",&H,&U,&D,&F),H)
    {
        i = 0;
        s = U;
        sum = 0;
        while(1)
        {
            i++;
            if(s > 0)//判断每天上升的距离大于0才会使总距离增加,不然就不会往上爬,当然也不会往下爬
                sum = sum + s;//如果没有上面的判断,则相当于有了向下爬的动力,这样和蜗牛的意愿就背道而驰了
            if(sum > H)
            {
                break;
            }
            sum = sum - D;
            if(sum < 0)
            {
                break;
            }
            s = s - F / 100 * U;
        }
        if(sum > H)
            printf("success on day %d\n",i);
        else
            printf("failure on day %d\n",i);
    }
    return 0;
}




Python 逆向解析知乎盐选反爬字体,实现内容精准还原 本文详细解析了知乎盐选内容的反爬字体机制,并提供了使用Python逆向解析WOFF字体文件的完整方案。通过fontTools库构建解码字典,实现乱码文本的精准还原,帮助开发者应对动态字体策略,同时强调法律与道德风险。 阅读详情

相关推荐

n8n 快速入门1:构建一个简单的工作流

n8n 快速入门指南

engchina的专栏 1万+

蜗牛爬井

蜗牛爬井 题目描述 有一口深度为h尺的井,有一只蜗牛从井底开 始往上爬。每个白天向上爬m(1≤m≤10)尺, 每个晚上又滑下来n(1≤n<m)尺。请你帮忙计 算一下,蜗牛第几天可以爬出来。 注:爬到和井口一样高也算爬出去。 输入 一行三个整数m、n、h。 输出 一个整数,表示第几天可以爬出来。 样例输入 3 2 10 样例输出 8 提示 对于 70% 的数据:10≤h≤1,000,000。 对于 100% 的数据:10≤h≤2,000,000,000。 题解: 注:本代码用的变量为网

Old flame.Scar 3937

Matlab+Matpower实战:手把手教你生成IEEE14节点FDIA攻击数据集(附完整代码)

本文提供了一份基于Matlab与Matpower工具构建IEEE14节点FDIA攻击数据集的完整实战指南。通过动态负荷数据模拟、潮流计算、状态估计及隐蔽攻击向量注入,手把手教你生成可用于电力系统网络安全研究的仿真数据集,并附有核心代码与调试技巧。

bean的博客 398

【C语言做题系列】The Snail

小菜鸡更新第一篇博客啦(有错希望能够指正且多多包涵哈)! 总结一下"回文数" 1. 数字回文数 就普通举例:‘12321’‘5665’之类的都是回文数(即每个数字正排序和逆排序的结果是一样的); 那怎么实现呢? 首先最容易想到的当然是 将 原数 的 逆序数 表示一遍 再判断两者是否相等。 那么有什么比较容易的算法可以简便地把上述步骤呈现出来呢? 来看一段代码片: int main() { ...

王保保的小博客 1049

大数据在电力行业的应用案例解析 -【电力技术】(十)电力数字化运营与大数据精准服务体系建设

电力数字化运营,是大数据在电力行业从技术场景走向业务价值的最终落点。它以数据为纽带,将用户、设备、服务、收益、风险全部纳入统一闭环,实现从 “管好电” 向 “运营好能源资产” 升级。在新型电力系统与市场化改革双重驱动下,谁能用好数据、建好闭环、做好运营,谁就能在服务、成本、效益、安全上建立长期优势。

getusushu的博客 69

静态代码审计插件 snyk 使用教程

静态代码审计插件 snyk 使用教程

SHELLCODE_8BIT的博客 2005

uva 573 - The Snail

The Snail  A snail is at the bottom of a 6-foot well and wants to climb to the top. The snail can climb 3 feet while the sun is up, but slides down 1 foot at night while sleeping. The snail h

uva code 1226

MATLAB基础应用精讲-【强化学习】Actor - Critic 算法(附python代码实现)

这种架构结合了策略梯度方法(Policy - Gradient Methods)和价值函数估计方法(Value Function Estimation Methods)的优点。在强化学习中,智能体(Agent)需要通过与环境(Environment)的交互来学习最优的行为策略,以获得最大的累积奖励(Cumulative Reward)。

qq_36130719的博客 363

高精度 C - The Snail

题目 A snail is at the bottom of a 6-foot well and wants to climb to the top. The snail can climb 3 feet while the sun is up, but slides down 1 foot at night while sleeping. The snail has a fatigue factor of 10%, which means that on each successive day the s

qq_45891413的博客 259

OD图 arcgis曲线制作插件 od图曲线 路径图曲线制作插件 航线图曲线制作插件

在ArcGIS 10.2 中导入节点数据,打开插件,选择输入起始节点和目标节点的节点文件Point,以Name字段(地名)为连接线的起始字段和目标字段,(Input Table File)选择连接关系表格SDLine.csv,(Origin Column 和 Destination Column)为起始节点和目标节点,(Output Path)为输出路径,应选择.gdb数据库路径,否则容易报错,(Chord Coefficient)为连线的曲率,数值越大,曲率越高。运行环境:ArcGIS10.2。...

JData_Engineer的博客 2670

Codex 100个真实案例 - 用AI生成建筑平面图SVG(室内设计师的新武器)

本案例用 Codex 生成一套完整的 Python 脚本,自动绘制 SVG 格式的建筑平面图。我们会设计一个90平两室一厅的户型——客厅、主卧、次卧、厨房、卫生间一应俱全,还会自动摆放家具(沙发、床、餐桌、橱柜)、标注尺寸和面积、绘制水电路走向、生成多种配色方案。最终输出的 SVG 文件可以直接用浏览器打开展示,也可以转成 PNG 交给客户。室内设计师看了都说好!

yueyeguzhuo的专栏 762

【HDU - 1302】The Snail (模拟,水题)

题干: A snail is at the bottom of a 6-foot well and wants to climb to the top. The snail can climb 3 feet while the sun is up, but slides down 1 foot at night while sleeping. The snail has a fatigue fa...

xuanweiace的博客 708

AutoSAR配置视频讲解:新建DaVinci工程

AutoSAR实验视频讲解:闪烁一颗LED实验【新建DaVinci工程】 上一篇 | 下一篇 | 总目录 实验架构图 视频本频放在了文末,下图描述了本次实验配置内容在AutoSAR架构中的位置,供大家参考 实验内容 本节课程讲解新建DaVinci工程,听上去新建工程很简单,但是还是需要很多的准备工作和细节。主要内容是新建工程和导入dbc文件和导入arxml文件的方法 主要步骤 新建DaVinci工程 导入.dbc通信矩阵文件 导入Mcal的arxml文件 实验视频2:Mcal配置 提示:版权所在,违

雪云飞星的博客 6276

The Snail

Description A snail is at the bottom of a 6-foot well and wants to climb to the top. The snail can climb 3 feet while the sun is up, but slides down 1 foot at night while sleeping. The snail has a fa

顺便A道题 1118

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

HDOJ 1302(UVa 573) The Snail(蜗牛爬井)

Problem Description A snail is at the bottom of a 6-foot well and wants to climb to the top. The snail can climb 3 feet while the sun is up, but slides down 1 foot at night while sleeping. The snail h

谙忆-陈浩翔 2620

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Snail-蜗牛

我的个人博客 更多内容,请跳转我的个人博客 题目 Snail 蜗牛 描述 Snail Sort Given an n x n array, return the array elements arranged from outermost elements to the middle element, traveling clockwise. 蜗牛排序 给定一个nxn数组,按顺时针方向返回从最外层元素排列到中间元素的数组元素。 如下面这个例子: array = [[1,2,3], [4,5,6],

huozheshusiqu的博客 504

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

The Snail【模拟】

A snail is at the bottom of a 6-foot well and wants to climb to the top. The snail can climb 3 feet while the sun is up, but slides down 1 foot at night while sleeping. The snail has a fatigue factor of 10%, which means that on each successive day the snai

既然弱小,就只顾变强就是了 379

【题目】[USACO5.2]蜗牛的旅行Snail Trails

[USACO5.2]蜗牛的旅行Snail Trails1

Mashiro_ylb的博客 1006

HDU1302:The Snail

Problem Description A snail is at the bottom of a 6-foot well and wants to climb to the top. The snail can climb 3 feet while the sun is up, but slides down 1 foot at night while sleeping. The snail

ACM!荣耀之路! 1957

The program design---The Snail

A snail is at the bottom of a 6-foot well and wants to climb to the top.The snail can climb 3 feet while the sun is up,but slides down 1 foot at night while sleeping.The snail has a fatigue factor of

smallmuou的专栏 953

杭电1302 The Snail

看到英语题是不是很头大,不要这样啦,其实这方面的英文题好简单的(我是说理解起来)首先要克服心理阴影,然后攻破它,算什么,对不对,你一定可以的 The Snail Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 2 Accepted Sub

acm学习讨论空间 791

uva 573 The Snail(模拟)

The Snail  A snail is at the bottom of a 6-foot well and wants to climb to the top. The snail can climb 3 feet while the sun is up, but slides down 1 foot at night while sleeping. The s

不慌不忙、不急不躁 1116

573 The Snail(蜗牛)

    The Snail    A snail is at the bottom of a 6-foot well and wants to climb to the top. The snail can climb 3 feet while the sun is up, but slides down 1 foot at night while sleep...

weixin_34399060的博客 171
上一篇: Box of Bricks ——平均数问题
下一篇: Steps——找规律
A_Happy_ACMer
博客等级 码龄12年 2粉丝 52原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值