题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1408

解题思路:主要考虑最后一滴可能不满足D毫升,但仍算1秒。另外还要注意浮点数的比较。

#include <cmath>
#include <iostream>
using namespace std;
#define epsilon 0.0000001
int main() {
double v, d, a;
int b;
while (cin >> v >> d) {
int n = , time = ;
while () {
//C语言比较两个浮点数,
//因为浮点数不恰好等于0,所以需要一个精度来确定是否相等
if (v - n*d > epsilon) {
v -= n*d;
time += n;
n++;
time++;
} else if (fabs(v - n*d) < epsilon) {
//差的绝对值小于精度0.0000001
v -= n*d;
time += n;
break;
} else {
a = v/d;
if (a - int(a) > epsilon) {
b = int(a) + ; //向上取整
} else {
b = int(a);
}
time += b;
break;
}
}
cout << time << endl;
}
return ;
}

HDU1408 - 盐水的故事的更多相关文章

  1. 盐水的故事[HDU1408]

    盐水的故事Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissio ...

  2. 盐水的故事(hdu1408)

    盐水的故事 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  3. C题 hdu 1408 盐水的故事

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1408 盐水的故事 Time Limit: 2000/1000 MS (Java/Others)     ...

  4. HDOJ(HDU) 1408 盐水的故事

    Problem Description 挂盐水的时候,如果滴起来有规律,先是滴一滴,停一下:然后滴二滴,停一下:再滴三滴,停一下-,现在有一个问题:这瓶盐水一共有VUL毫升,每一滴是D毫升,每一滴的速 ...

  5. hdu 1408 盐水的故事

    Problem Description 挂盐水的时候,如果滴起来有规律,先是滴一滴,停一下:然后滴二滴,停一下:再滴三滴,停一下...,现在有一个问题:这瓶盐水一共有VUL毫升,每一滴是D毫升,每一滴 ...

  6. 6J - 盐水的故事

    挂盐水的时候,如果滴起来有规律,先是滴一滴,停一下:然后滴二滴,停一下:再滴三滴,停一下...,现在有一个问题:这瓶盐水一共有VUL毫升,每一滴是D毫升,每一滴的速度是一秒(假设最后一滴不到D毫升,则 ...

  7. 题解报告:hdu 1408 盐水的故事

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1408 Problem Description 挂盐水的时候,如果滴起来有规律,先是滴一滴,停一下:然后 ...

  8. HDU 1408 盐水的故事 数学水题

    http://acm.hdu.edu.cn/showproblem.php?pid=1408 题目: 挂盐水的时候,如果滴起来有规律,先是滴一滴,停一下:然后滴二滴,停一下:再滴三滴,停一下...,现 ...

  9. 【HDOJ】1408 盐水的故事

    简单题,感觉非常简单,像小学奥数的植树问题. #include <stdio.h> #include <math.h> #define MAXNUM 5001 int main ...

随机推荐

  1. remote: error: hook declined to update refs/heads

    打开工程目录下.git/config文件,补充user信息 , [user] username = xxx email = xxx@126.com 打开工程目录下.git/description文件, ...

  2. Codeforces_723_A

    http://codeforces.com/problemset/problem/723/A 取中间那个数就可以了,答案为最大值减最小值. #include<iostream> #incl ...

  3. HDU6183 Color it (线段树动态开点)

    题意: 一个1e6*1e6的棋盘,有两个操作:给(x,y)加上颜色c,或查找(1,y1)到(x,y2)内的颜色种类数量,最多有50种颜色 思路: 建立50颗线段树,对每个颜色的线段树,维护每个y坐标上 ...

  4. Pycharm学习记录---同一目录下无法import明明已经存在的.py文件

    转自:https://blog.csdn.net/l8947943/article/details/79874180 问题描述: 如图:同目录下明明存在相应文件,在导入时却出现带有红色波浪线,说没有相 ...

  5. 【阿里云IoT+YF3300】14.阿里IoT Studio打造手机端APP

    在上一篇<13.阿里云IoT Studio WEB监控界面构建>中,我们介绍了用阿里云IoT Studio(原Link Develop)可视化构建WEB界面程序.本篇文章将介绍用阿里云Io ...

  6. [RAC] 1. 安装Oracle RAC时,不能验证ASMSNMP密码问题的解决(ORA-01031或ORA-01017)

      1."ORA-01031: insufficient privileges" [grid@node1 bin]$ orapwd file=/u01/app/11.2.0/gri ...

  7. SAXParseException Content is not allowed in Prolog (前言中不允许有内容)

    解析 XML 文件的时候,如 Mybatis 的 Mapper 文件,有时会出现 org.xml.sax.SAXParseException 前言中不允许有内容 的异常,英文就是 Content is ...

  8. PWA 学习笔记

    深入学习网址:https://developer.mozilla.org/zh-CN/docs/Web/Progressive_web_apps 一. 基本介绍 1. 渐进式:适用所有浏览器,因为它是 ...

  9. 1236 - Pairs Forming LCM

    1236 - Pairs Forming LCM   Find the result of the following code: long long pairsFormLCM( int n ) {  ...

  10. git报错:fatal: No configured push destination.

    本地仓库代码(git push)上传git仓库报错: fatal: No configured push destination. Either specify the URL from the co ...