HDU-1049 Climbing Worm

简介: HDU-1049 Climbing Worm

题目:

description:

An inch worm is at the bottom of a well n inches deep. It has enough  energy to climb u inches every minute, but then has to rest a minute  before climbing again. During the rest, it slips down d inches. The  process of climbing and resting then repeats. How long before the worm  climbs out of the well? We’ll always count a portion of a minute as a  whole minute and if the worm just reaches the top of the well at the end  of its climbing, we’ll assume the worm makes it out.

Input:

There will be multiple problem instances. Each line will contain 3  positive integers n, u and d. These give the values mentioned in the  paragraph above. Furthermore, you may assume d < u and n < 100. A  value of n = 0 indicates end of output.

Output:

Each input instance should generate a single integer on a line,  indicating the number of minutes it takes for the worm to climb out of  the well.

Sample Input

10 2 1

20 3 1

0 0 0

Sample Output

17

19

解析:

1. 题目,有一只虫子从井里底像上爬,井深n,每分钟爬d,每次休息一分钟,休息时往下下降u.输入 n d u 输出虫子爬出井的时间

#include<stdio.h>
int main()
{
    int n,u,d,time1,time2,count;
    while(scanf("%d %d %d",&n,&u,&d),n+u+d)
    {
        count=0;
        time1=time2=0;
        while(count<=n)
        {
            count=count+u;
            time1+=1;//累加向上爬的时间
            if(count>=n)break;
            count=count-d;
            time2+=1;//累加休息的时间
        }
        printf("%d\n",time1+time2);
    }
    return 0;
}

半夏话前端                

                 微信公众号                  

             帮助更多人成长!    

关注

相关文章
|
Linux 开发工具 Windows
中国时间服务器,国内阿里云时间服务器
中国时间服务器,国内阿里云时间服务器很多用户使用的是国外VPS使用过程中常常遇到时间与国内不同步的情况好在阿里提供了7台NTP服务器,地址如下:阿里云提供了7个NTP时间服务器也就是Internet时间同步服务器地址 ntp1.
41109 0
|
语音技术 C语言
基于树莓派的智能音响【报时】【放歌】【切歌】【开关灯】
基于树莓派的智能音响【报时】【放歌】【切歌】【开关灯】
358 0
基于树莓派的智能音响【报时】【放歌】【切歌】【开关灯】
|
安全 Windows
修改windows系统文件权限
修改windows系统文件总是提示没有权限,虽然已是administrator也不管用。 以下方法可以解决: 右键属性,安全,高级,所有者,编辑,选择当前用户并确定, 回到上一页再确定, 然后在安全页面点编辑,添加,高级,立即查找,找到当前用户,并确定, 回到安全页面,选择当前用户,给予完全控制权限,最后确定, 以上操作就是把文件所有者设为当前用户,并且给予完全控制的权限。
2014 0
|
2天前
|
云安全 人工智能 算法
以“AI对抗AI”,阿里云验证码进入2.0时代
三层立体防护,用大模型打赢人机攻防战
1292 1
|
9天前
|
编解码 人工智能 自然语言处理
⚽阿里云百炼通义万相 2.6 视频生成玩法手册
通义万相Wan 2.6是全球首个支持角色扮演的AI视频生成模型,可基于参考视频形象与音色生成多角色合拍、多镜头叙事的15秒长视频,实现声画同步、智能分镜,适用于影视创作、营销展示等场景。
698 4
|
2天前
|
机器学习/深度学习 安全 API
MAI-UI 开源:通用 GUI 智能体基座登顶 SOTA!
MAI-UI是通义实验室推出的全尺寸GUI智能体基座模型,原生集成用户交互、MCP工具调用与端云协同能力。支持跨App操作、模糊语义理解与主动提问澄清,通过大规模在线强化学习实现复杂任务自动化,在出行、办公等高频场景中表现卓越,已登顶ScreenSpot-Pro、MobileWorld等多项SOTA评测。
543 2
|
3天前
|
人工智能 Rust 运维
这个神器让你白嫖ClaudeOpus 4.5,Gemini 3!还能接Claude Code等任意平台
加我进AI讨论学习群,公众号右下角“联系方式”文末有老金的 开源知识库地址·全免费