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. 计时器60s

    计时器是经常用到的功能,下面以react nativ的例子简介来写一个倒计时60s的小demo. 代码如下: import React, { Component } from 'react'; imp ...

  2. 解密SuperWebview的一种另类方法

    解密SuperWebview的一种另类方法 什么是SuperWebview SuperWebview是APICloud官方推出的另一项重量级API生态产品,以SDK方式提供,致力于提升和改善移动设备W ...

  3. git视频教程

    git 精简版视频教程-2小时快速入门精华版,小教程很快就可以看完. 旺旺 QQ:Git是目前世界上最先进的分布式版本控制系统(没有之一). Git有非常高的逼格,简单来说就是:高端大气上档次. 这么 ...

  4. ubuntu 16.04.2 源码安装gitlab并且利用runner持续集成

    参考原档:https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/install/installation.md#using-https 本章只 ...

  5. win7休眠的开启与关闭方法

    从开始菜单中找到“附件→命令提示符”,右击选择“以管理员身份运行”,此时可能需要输入管理员密码或进行UAC确认,手工输入如下命令:powercfg -a,从这里可以清楚的看到,计算机是支持休眠的,只是 ...

  6. 如何解决苹果Mac系统无法识别U盘

       1.在Mac机上打开“磁盘工具”,将U盘重新分区, 2.格式选“exFAT”.该格式分区Win及Mac系统中都可以读和写,特别是可以支持大于4GB的大文件.但是一些高清播放机可能不支持. 3.以 ...

  7. Spring Boot快速入门

    安装 安装依赖 maven是一个依赖管理工具,我们利用maven进行构建.创建一个maven项目,在pom.xml里面添加依赖项 <?xml version="1.0" en ...

  8. 获取元素到body/html的距离函数

    获取元素到body的距离: <script> function offsetDis(obj) { var l = 0, t = 0; while(obj) { l = l + obj.of ...

  9. Windows10 Enterprise版本周年更新问题

    安装Windows10的时候,蛋疼选择了企业版本,导致后来周年更新遇到了蛋疼的问题. 首先是无法接收到周年更新的推送.记得首个周年更新的时候,等了大半年都没有.后来使用了易升进行更新,可以检测到,但是 ...

  10. Vijos 1040 高精度乘法

    描述 高精度乘法 输入:两行,每行表示一个非负整数(不超过10000位) 输出:两数的乘积. 样例1 样例输入1 99 101 样例输出1 9999 题解 这道题和之前的Vijos 1010 清帝之惑 ...