http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=494
题目大意:
一只蜗牛要从爬上n英寸高的地方,他速度为u每分钟,他爬完u需要休息1分钟,且他休息时下滑d英寸,问他什么时候爬出去。
吐槽:
小学的数学题编程了编程题,简直丧心病狂。
思路:
数据量小直接模拟即可。
也可以用数学推导
模拟板:
#include<cstdio>
int main()
{
int n,u,d;
while(~scanf("%d%d%d",&n,&u,&d),n||u||d)
{
int h=0;
int ans=0;
while(h<n)
{
ans++;
h+=u;
if(h >=n)
break;
ans++;
h-=d;
}
printf("%d\n",ans);
}
return 0;
}
公式版:
#include<cstdio>
int main()
{
int n,u,d;
while(~scanf("%d%d%d",&n,&u,&d),n||u||d)
{
int h=0;
double temp=double(n-d)/double(u-d);
int ans;
if(temp - (int) temp< 1e-12)
ans=temp;
else
ans=temp+1;
printf("%d\n",2*ans-1);
}
return 0;
}
本文探讨了一道看似简单的数学问题——蜗牛如何从一定高度爬出去,涉及基本的数学运算和逻辑思考。通过编程实现,不仅解答了问题,还展示了将数学概念应用到实际情境的方法。
1175

被折叠的 条评论
为什么被折叠?



