挂盐水的时候,如果滴起来有规律,先是滴一滴,停一下;然后滴二滴,停一下;再滴三滴,停一下…,现在有一个问题:这瓶盐水一共有VUL毫升,每一滴是D毫升,每一滴的速度是一秒(假设最后一滴不到D毫升,则花费的时间也算一秒),停一下的时间也是一秒这瓶水什么时候能挂完呢?
代码C:
#include<stdio.h>
#include<math.h>
int main()
{
int t;
double x,y,i,count;
while(scanf("%lf%lf",&y,&x)!=EOF)
{
count=0;//代表滴下的总体积
for(i=1;i<5000;i++)//代表第i次滴下多少滴
{
count=count+i*x;//滴下的总体积
if(i*x+x>(y-count))//如果理论上最后一次滴下的量多于剩余的量就不滴
break;
}
if(y-count==0)
i=i--;
if((y/x)>(int)(y/x))
t=(int)(y/x)+1;
else
t=y/x;
printf("%d\n",t+(int)i);
}
return 0;
}