题目链接:https://vjudge.net/problem/HDU-1408
分析:这题要注意精度,double的精度。
模拟每一步滴水的过程:
1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <iostream> 5 #include <algorithm> 6 #include <string> 7 #include <cstdlib> 8 9 using namespace std; 10 11 int main() 12 { 13 double V, D; 14 int t, i; 15 int num; 16 while(scanf("%lf%lf", &V, &D) != EOF) 17 { 18 t = 0; 19 num = 1; 20 while(1) 21 { 22 for(i = 1; i <= num; ++i) 23 { 24 V -= D; 25 t++; 26 if(V <= 0.0000001) 27 break; 28 } 29 if(V <= 0.0000001) break; 30 t++; 31 num++; 32 } 33 printf("%d ", t); 34 } 35 return 0; 36 }