挂盐水的时候,如果滴起来有规律,先是滴一滴,停一下;然后滴二滴,停一下;再滴三滴,停一下...,现在有一个问题:这瓶盐水一共有VUL毫升,每一滴是D毫升,每一滴的速度是一秒(假设最后一滴不到D毫升,则花费的时间也算一秒),停一下的时间也是一秒这瓶水什么时候能挂完呢?
Input
输入数据包含多个测试实例,每个实例占一行,由VUL和D组成,其中 0<D<VUL<5000。
Output
对于每组测试数据,请输出挂完盐水需要的时间,每个实例的输出占一行。
Sample Input
10 1
Sample Output
13
#include <iostream>
#include <bits/stdc++.h>
#include <string.h>
#include <math.h>
using namespace std;
int main()
{
int c,d;
double a,b;//此处必须要用double,不一定是整数
while(cin >> a >> b)
{
c=0;
d=1;
while(a-d*b>0.000001)
{
c=c+d+1;
a=a-d*b;
d++;
}
if(a-(int)(a/b)*b<0.000001)
{
c=c+a/b;
}
else
{
c=c+a/b+1;
}
cout << c << endl;
}
return 0;
}
#include <stdio.h>
int main()
{
int count,t2;
double vul,d,t1,sum,t;
while(scanf("%lf%lf",&vul,&d)!=EOF)
{
t=vul/d;
count=0;
sum=0;
while(1)
{
count++;
if (sum+count>=t)
{
break;
}
else
{
sum+=count;
}
}
t1=t-sum;
t2=int(t1);
if ((double)t2!=t1)
{
t2++;
}
t=sum+count+t2-1;
printf("%d\n",(int)t);
}
return 0;
}