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
 
Code:
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <ctype.h> using namespace std; int main()
{
int n,u,d;
while(scanf("%d%d%d",&n,&u,&d)&&n&&u&&d)
{
int res=n,t=;
res-=u;
while(res)
{
if(t>=)
{
res-=u;
t++;
}
if(res<=)
break;
res+=d;
t++;
}
printf("%d\n",t);
}
return ;
}

HDU1049的更多相关文章

  1. HDU-1049

    Description An inch worm is at the bottom of a well n inches deep. It has enough energy to climb u i ...

  2. ACM训练计划建议(写给本校acmer,欢迎围观和指正)

    ACM训练计划建议 From:freecode#  Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...

  3. OJ题目分类

    POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006 POJ1008 POJ1013 P ...

  4. ACM训练计划建议(转)

    ACM训练计划建议 From:freecode#  Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...

随机推荐

  1. EF Core学习Code First

    下面通过实例来学习EF Core Code First,也就是通过EF Core迁移来完成从模型生成数据库. 本实例使用EntityFrameworkCore SQLite 数据库进行介绍,大家也可以 ...

  2. 格式化输出和printf命令

    GNU版本的printf命令用来格式化输出,效果类似与C语言的printf函数.2.x以上版本的Bash内建的printf命令和e/usr/bin下的printf命令使用方法一样. 例子:$print ...

  3. 在Windows上远程运行Linux程序

    1.在Windows主机上安装X Server软件,如Cygwin带的XWin Server 2.在Windows主机上启动X服务器,并将Linux主机设为允许访问该Windows主机上的X服务器. ...

  4. ubuntu eclipse 建立server 提示coud not load the tomcat server configuration at /opt/apache ...的解决方法

    ubuntu eclipse 建立server 提示coud not load the tomcat server configuration at /opt/apache ...的解决方法 & ...

  5. Rails核心组件

    Action Pack 包含Action Controller,Action View,Action Dispatch 封装了MVC的VC功能 Action Mailer 开发电子邮件服务的框架 Ac ...

  6. docker 私有仓库搭建

    知识基础:ubuntu系统安装,docker安装,了解docker的基础知识 下载镜像(如果下载2版本以上的需要配置ssl证书,这里先用0.9.1的演示) root@ubuntu:/# docker ...

  7. TortoiseGit使用SSH

    Windows TortoiseGit使用SSH连接 1 找到TortoiseGit自带的Puttygen工具 2.1 如果未生成过SSHKey,选择Generate(生成的过程中记得移动鼠标) 2. ...

  8. 【Android Developers Training】 60. 在你的UI中显示位图

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

  9. 9.session的生命周期

    1.创建 当客户端第一次访问某个jsp或者Servlet的时候,服务器会为当前会话创建一个SessionId,每次客户端向服务端发送请求的时候,都会将此SessionId携带过去,服务端会对此Sess ...

  10. CSS 实现流布局以及多列混合布局

    基本流布局 <!DOCTYPE html > <html> <head> <meta charset="utf-8"> <ti ...