Climbing Worm

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 19841    Accepted Submission(s): 13532

Problem 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
 
Source
 
Recommend

We have carefully selected several similar problems for you:  1021 1019 1071 1009 1061

Problem : 1049 ( Climbing Worm )     Judge Status : Accepted

RunId : 21270620    Language : G++    Author : hnustwanghe

Code Render Status : Rendered By HDOJ G++ Code Render Version 0.01 Beta

#include<iostream>
#include<cstring>
#include<cstdio>

using namespace std;

int main(){
int u,n,d,time;
while(scanf("%d %d %d",&n,&u,&d)==3 && (n||u||d)){
time = 1;
while(n-u>0){
time+=2;
n=n-u+d;
}
printf("%d\n",time);
}
}

#include<iostream>
#include<cstring>
#include<cstdio>

using namespace
std; int main(){
int
u,n,d,time;
while(
scanf("%d %d %d",&n,&u,&d)==3 && (n||u||d)){
time = 1;
while(
n-u>0){
time+=2;
n=n-u+d;
}

printf("%d\n",time);
}
}

思维体操: HDU1049Climbing Worm的更多相关文章

  1. 思维体操: HDU1287破译密码

    破译密码 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  2. 思维体操: HDU1008 Elevator

    Elevator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  3. 思维体操: HDU1022Train Problem I

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. 2.Web开发过程流程图

    转自:https://blog.csdn.net/hello_simon/article/details/19993343 最近公司在进行一系列新模块的开发,在痛苦开发的过程中,大家不时在一起进行总结 ...

  5. 题解-Koishi Loves Construction

    题解-Koishi Loves Construction 前缀知识 质数 逆元 暴搜 Koishi Loves Construction 给定 \(X\),\(T\) 组测试数据,每次给一个 \(n\ ...

  6. &&与||的优先级比较

    &&与||的优先级比较类似于一种思维体操,更多的是造成矛盾,使得两者因为先后顺序的不同而造成的不同结果,当然有时候需要注意c语言中的短路运算. 方法1. 代码如下: 点击查看代码 #i ...

  7. [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序

    用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html  目录 马桶排序(令人 ...

  8. Photoshop、Illustrator思维导图笔记

    半年前学习Photoshop时记得的思维导图笔记,可能不是很全,常用的基本都记下了.

  9. CYQ.Data 从入门到放弃ORM系列:开篇:自动化框架编程思维

    前言: 随着CYQ.Data 开始回归免费使用之后,发现用户的情绪越来越激动,为了保持这持续的激动性,让我有了开源的念头. 同时,由于框架经过这5-6年来的不断演进,以前发的早期教程已经太落后了,包括 ...

随机推荐

  1. Python 爬虫十六式 - 第五式:BeautifulSoup-美味的汤

    BeautifulSoup 美味的汤 学习一时爽,一直学习一直爽!    Hello,大家好,我是Connor,一个从无到有的技术小白.上一次我们说到了 Xpath 的使用方法.Xpath 我觉得还是 ...

  2. jquery gt选择器 语法

    jquery gt选择器 语法 作用::gt 选择器选取 index 值高于指定数的元素.index 值从 0 开始.经常与其他元素/选择器一起使用,来选择指定的组中特定序号之后的元素(如上面的例子) ...

  3. tomcat8 的优化

    1.下载tomcat8 2.配置 修改tomcat_user.xml,配置管理用户(设置角色,和用户密码) <role rolename="manager"/> < ...

  4. CodeForces 1200E Compress Words

    \(C_n^m\)的typora,点了一下启用源代码模式就把我已经写好的博客弄没了,就给我留个标题,自动保存也只给我保存了个标题--\(C_n^m\),wdnmd Time limit 1000 ms ...

  5. (C#- 多线程) 在线程中创建object,共享问题。

    研究如下问题: 1. 在一个进程的主线程中创建一个Object,其他线程都可以访问这个Object,并操作Object的方法. - 多线程同步问题. 2. 在一个进程的多个线程里面,每个线程都创建同一 ...

  6. 【技术分享:python 应用之三】使用 python 修改 excel 表格的 sheet 名称

    原始需求:已经下载好了 Excel 文件,但是 Excel 里的 sheet 的名称想要修改一下,比如原本默认的是sheet1,需要修成“DNEWCD_JQJSHMX”.需求比较简单,直接上代码吧! ...

  7. QtCreator常用之快捷键

    1. Ctrl(按住)+ Tab快速切换已打开的文件 2. 自动添加成员函数实体(.cpp)定义: 将光标移动到h文件中的方法声明. 按Alt(按住)+ Enter,再按回车键 将在cpp中添加该函数 ...

  8. sqli-labs(18)

    开始挑战第十八关(Header Injection - Uagent field - Error based) 常见的HTTP注入点产生位置为[Referer].[X-Forwarded-For].[ ...

  9. How to Create a Basic Plugin 如何写一个基础的jQuery插件

    How to Create a Basic Plugin Sometimes you want to make a piece of functionality available throughou ...

  10. C# 读写App.config 配置文件

    先要添加引用:System.Configuration //using System.Configuration; if (System.IO.File.Exists(AppDomain.Curren ...