HDU 1408 盐水的故事 数学水题

时间:2022-01-10 19:52:02

http://acm.hdu.edu.cn/showproblem.php?pid=1408

题目:

挂盐水的时候,如果滴起来有规律,先是滴一滴,停一下;然后滴二滴,停一下;再滴三滴,停一下...,现在有一个问题:这瓶盐水一共有VUL毫升,每一滴是D毫升,每一滴的速度是一秒(假设最后一滴不到D毫升,则花费的时间也算一秒),停一下的时间也是一秒这瓶水什么时候能挂完呢?

一开始Output Limit Exceeded 第一次遇到。。。。

好吧,不知道是什么原因,看了下别人的。。人家是double我是Int,好吧,改了就AC了,QAQ

#include<cstdio>
int main()
{
double v,d;
while(~scanf("%lf%lf",&v,&d))
{
int cur=1;
int ans=0;
while(v>0)
{
for(int i=0;i<cur;i++)
{
v-=d;
ans++;
if(v<=0)
goto end;
}
cur++;
ans++;
}
end:
printf("%d\n",ans);
}
return 0;
}