hdu 1049 Climbing Worm

解题思路:
1. 两种情况,0x1:井深度小于一次跳的高度.0x2:井深度大于一次跳的高度
2.如果 属于 0x1 则一次跳出
3.否则 本次解题中直接枚举跳的次数
一直循环,直到 【每次跳的真实高度(一次高度减去滑下的高度)】*【次数(循环)】+【最后一次(一次的高度)】大于等于井深度
得到次数
4. 输出:次数*2+1
次数*2:每跳一次,休息一分钟
+1 :最后一跳,直接跳出井
Ac code:
#include<stdio.h>
int main(void)
{
int n,u,d;
int sum,i;
while(scanf("%d%d%d",&n,&u,&d)!=EOF&&n)
{
if(n<=u)sum=1;
else
{
for(i=1;; i++)
if(n<=((u-d)*i+u))
break;
sum=2*i+1;
}
printf("%d\n",sum);
}
return 0;
}
错误版本,求大神指正:
sum 可以看成求得次数。
(n-u):去掉最后一跳
(u-d):每次跳的真实高度
取得最后一跳 / 每次的高度 , 并强制转换成 double +0.5
举例:
n=10 u=2 d=1: 8 / 1 +0.5 =8 ->8*2+1=17
n=20 u=3 d=1: 17 /2 +0.5=9->9*2+1=19
错的不知所云
#include<stdio.h>
int main(void)
{
int n,u,d;
int sum;
while(scanf("%d%d%d",&n,&u,&d)!=EOF&&n)
{
sum=(int)(((double)(n-u)/(u-d))+0.5);
printf("%d\n",sum*2+1 );
}
return 0;
}
经Taskr同学提醒: 10 9 1 该组测试数据发现问题
修正版AC代码:
#include<stdio.h>
int main(void)
{
int n,u,d;
int sum;
while(scanf("%d%d%d",&n,&u,&d)!=EOF&&n)
{
sum=ceil(((double)(n-u)/(u-d))); //仅修改了本行
printf("%d\n",sum*+ );
}
return ;
}
hdu 1049 Climbing Worm的更多相关文章
- Climbing Worm
Climbing Worm Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 【hdoj_1049】Climbing Worm
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1049 以 上升-下降 一次为一个周期,一个周期时间为2分钟,每个周期上升距离为(u-d).先只考虑上升,再 ...
- HDU 4315 Climbing the Hill (阶梯博弈转尼姆博弈)
Climbing the Hill Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Su ...
- hdu 4315 Climbing the Hill(阶梯博弈转nim博弈)
Climbing the Hill Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 4315 Climbing the Hill(阶梯博弈)
http://acm.hdu.edu.cn/showproblem.php?pid=4315 题意:由上至下有多个格子,最顶端的是山顶,有多个球,其中有一个球是king,每次可以将球向上移动任意个格子 ...
- HDU 2782 The Worm Turns (DFS)
Winston the Worm just woke up in a fresh rectangular patch of earth. The rectangular patch is divide ...
- hdu 4315 Climbing the Hill && poj 1704 Georgia and Bob阶梯博弈--尼姆博弈
参考博客 先讲一下Georgia and Bob: 题意: 给你一排球的位置(全部在x轴上操作),你要把他们都移动到0位置,每次至少走一步且不能超过他前面(下标小)的那个球,谁不能操作谁就输了 题解: ...
- hdu 4315 Climbing the Hill 博弈论
题意:有n个人爬山,山顶坐标为0,其他人按升序给出,不同的坐标只能容纳一个人(山顶不限),Alice和Bob轮流选择一个人让他移动任意步,但不能越过前面的人,且不能和前面一个人在相同的位置.现在有一个 ...
- HDU 4315 Climbing the Hill [阶梯Nim]
传送门 题意: 和上题基本一样:山顶可以有多人,谁先把king放到山顶谁就胜 并不太明白 #include <iostream> #include <cstdio> #incl ...
随机推荐
- Ubuntu优化-py用机器
关闭防火墙 ufw disable pip换源 yum install python-pip -y mkdir ~/.pip cat > pip.conf<<a [global] i ...
- svn命令行修改已提交的版本备注
svn命令行修改已提交的版本备注 参考文章: stackoverflow.com/questions/304383/how-do-i-edit-a-log-message-that-i-already ...
- .NET编译的目标平台(AnyCPU,x86,x64)
转载:http://blog.sina.com.cn/s/blog_78b94aa301014i8r.html 今天有项目的代码收到客户的反馈,要求所有的EXE工程的目标平台全部指定成x86,而所有D ...
- Go视频教程整理
[Go Web基础]01博客项目设计 |Go视频教程|Go语言基础 http://www.tudou.com/programs/view/gXZb9tGNsGU/ [Go Web基础]02初窥 Web ...
- Gradle tip #1: tasks
With this post I would like to start series of Gradle-related topics I wish I knew when I first star ...
- Windows10+Ubuntu双系统安装[多图]
最近因为毕设重新回归Ubuntu,手头有一台装了Win10的ThinkPad X240s,最终成功完成了Windows 10 教育版和Ubuntu Kylin 15.10 的双系统配置,下文(多图慎入 ...
- [CareerCup] 4.4 Create List at Each Depth of Binary Tree 二叉树的各层创建链表
4.4 Given a binary tree, design an algorithm which creates a linked list of all the nodes at each de ...
- js浮点数精确计算(加、减、乘、除)
<SPAN style="FONT-SIZE: 18px">//说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显.这个函数返回较为精确的加 ...
- GDB堆栈跟踪与汇编调试
GDB堆栈跟踪与汇编调试 堆栈跟踪 源代码: 对预先编写的 stack.c 文件进行编译,并且使用 CGDB 进行调试,对堆栈进行跟踪,了解该代码堆栈是如何变化的. 在 CGDB 中,先设置 main ...
- 浩瀚先森(guohao1206.com)
博客搬家啦,新博客地址:浩瀚先森 http://www.guohao1206.com