思路:要注意v,d都可以是实数
代码如下:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
using namespace std;
int f(double v, double d)
{
int t, cs, temp;
t = 0;
cs = temp = 1;
while (v)
{
while (cs--)
{
v -= d;
t++;
if (v <= 0.0000001)
{
return t;
}
}
temp++;
cs = temp;
t++;
}
}
int main()
{
double v, d;
int t;
int cs;
int temp;
while (cin >> v >> d)
{
printf("%d\n", f(v, d));
}
system("pause");
return 0;
}