http://acm.hdu.edu.cn/showproblem.php?pid=1408
精度问题
![ContractedBlock.gif](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
#include
"
iostream
"
using namespace std;
int main()
{
double v,d;
while (cin >> v >> d)
{
int l = v / d; // l为所滴的滴数
if (l != v / d) l ++ ; // +1表示最后一滴小于d,也算成一滴
double sum = 0 ;
int t = 0 ; // 记录间隔数
int i = 1 ;
while (sum < l) // 已有的滴数和总的滴数比较
{
sum += i;
t ++ ;
i ++ ;
}
cout << t + l - 1 << endl;
}
return 0 ;
}
using namespace std;
int main()
{
double v,d;
while (cin >> v >> d)
{
int l = v / d; // l为所滴的滴数
if (l != v / d) l ++ ; // +1表示最后一滴小于d,也算成一滴
double sum = 0 ;
int t = 0 ; // 记录间隔数
int i = 1 ;
while (sum < l) // 已有的滴数和总的滴数比较
{
sum += i;
t ++ ;
i ++ ;
}
cout << t + l - 1 << endl;
}
return 0 ;
}
转载于:https://www.cnblogs.com/FCWORLD/archive/2011/04/04/2005024.html