zoukankan      html  css  js  c++  java
  • (HDU)1408 -- 盐水的故事

    题目链接: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 }
  • 相关阅读:
    树的重心备忘
    Hdu 2196
    HDU 1520
    TOJ1068 商务旅行
    携程HDU第一场1001
    USACO 4.3.2 The Primes
    Html常用标签的应用
    Html
    开班心得
    for循环练习及字符串处理
  • 原文地址:https://www.cnblogs.com/ACDoge/p/6141001.html
Copyright © 2011-2022 走看看