博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1049 Climbing Worm(水题)
阅读量:6907 次
发布时间:2019-06-27

本文共 1448 字,大约阅读时间需要 4 分钟。

Climbing Worm

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

Total Submission(s): 7047    Accepted Submission(s): 4455

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
 
 
 
水题。
总长为n,上升一秒走u,休息一秒下降d.
相当于每两秒走(u-d);
先n-u,得到过了多少个u-d后超过n-u;
int t=(n-u)/(u-d);
        if(t*(u-d)<(n-u)) t++;
        t*=2;
        t++;
就是最后一秒可以一步到达~~~
代码:
#include
int main() {
int n,u,d; while(scanf("%d%d%d",&n,&u,&d),n) {
int t=(n-u)/(u-d); if(t*(u-d)<(n-u)) t++; t*=2; t++; printf("%d\n",t); } return 0; }

转载地址:http://rngdl.baihongyu.com/

你可能感兴趣的文章
Ubuntu安装OpenSSL
查看>>
检查HP服务器内存状态脚本
查看>>
string.punctuation
查看>>
Linux运维 第二阶段 (十二) 进程管理
查看>>
在MWC2018上看工业互联网走向
查看>>
互联网产品常用英语单词
查看>>
实验一 分治与递归—用分治法实现元素选择 java算法
查看>>
HMGET key field [field ...]
查看>>
C++ Internals: STL之Map
查看>>
JQuery中$.ajax()方法参数详解(转载)
查看>>
汇编程序:按键松开时中断的处理
查看>>
统计一个网段以及相应区段存活和宕机的ip
查看>>
Mysql 通过全量备份和binlog恢复整体数据
查看>>
单点登录
查看>>
jQuery Template 简单使用
查看>>
Internet路由之路由表查找算法概述-哈希/LC-Trie树/256-way-mtrie树
查看>>
Centos网络管理(四)-路由转发与静态路由
查看>>
企业数据囤积是小事?Veritas的《数据囤积报告》告诉你千万别小看这些风险
查看>>
python链接mysql常见问题汇总
查看>>
UDP"打洞"原理
查看>>