题意:有一壶水, 体积在 LLLRRR 之间, 有两个杯子, 你要把水倒到两个杯子里面, 使得杯子水体积几乎相同(体积的差值小于等于1),

并且使得壶里剩下水体积不大于1. 你无法测量壶里剩下水的体积, 问最小需要倒水的次数。

析:考虑倒水的大致过程,不妨设 L > 0。首先向一个杯子倒 L/2 ​2​​L​​ 升水,再往另一个杯子倒 L/2+1​2​​L​​+1 升水。接下来就来回往两个杯子里倒 2 升,

直到倒空为止。这样就很容易分析出需要倒水的次数。唯一注意的是最后壶里面可以剩下 1 升水,可以省一次倒水的操作。

就是一步一步的模拟就可以,注意特殊情况,并且这个特殊情况较多。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
} int main(){
LL l, r;
while(scanf("%I64d %I64d", &l, &r) == 2){
if(!l){
if(r <= 1) printf("0\n");
else printf("%I64d\n", (r+1)/2);
}
else if(1 == l){
if(r == 1) printf("0\n");
else printf("%I64d\n", (1+r)/2);
}
else if(2 == l){
if(r == 2) printf("1\n");
else if(r >= 3 && r <= 5) printf("2\n");
else printf("%I64d\n", (r-l-2)/2+2);
}
else{
LL ans = 2;
ans += (r-l-2)/2;
ans = Max(ans, 2LL);
printf("%I64d\n", ans);
}
}
return 0;
}

HDU 5881 Tea (模拟)的更多相关文章

  1. hdu 5881 Tea (2016 acm 青岛网络赛)

    原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5881 Tea Time Limit: 3000/1000 MS (Java/Others)    Me ...

  2. HDU 5881 Tea

    Tea Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  3. HDU 5881 Tea -2016 ICPC 青岛赛区网络赛

    题目链接 题意:有一壶水, 体积在 L和 R之间, 有两个杯子, 你要把水倒到两个杯子里面, 使得杯子水体积几乎相同(体积的差值小于等于1), 并且使得壶里剩下水体积不大于1. 你无法测量壶里剩下水的 ...

  4. Tea HDU - 5881

    Tea is good. Tea is life. Tea is everything. The balance of tea is a journey of pursuing balance of ...

  5. HDU 4121 Xiangqi 模拟题

    Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...

  6. hdu 5071 Chat(模拟)

    题目链接:hdu 5071 Chat 题目大意:模拟题. .. 注意最后说bye的时候仅仅要和讲过话的妹子说再见. 解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A ...

  7. hdu 4740【模拟+深搜】.cpp

    题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇. ...

  8. HDU 2568[前进]模拟

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2568 关键思想:傻傻地模拟 代码如下: #include<iostream> using ...

  9. hdu 4964 恶心模拟

    http://acm.hdu.edu.cn/showproblem.php?pid=4964 给定语句,按照语法翻译html并输出. 就是恶心的模拟,递归搞就行了 处理id和class时,在一个'&g ...

随机推荐

  1. git-flow 工作流 备忘清单

    关于 git-flow 是一个 git 扩展集,按 Vincent Driessen 的分支模型提供高层次的库操作. 查看详情 ★ ★ ★ 这个备忘清单展示了 git-flow 的基本操作和效果. ★ ...

  2. linux 源码编译安装apache

    cc1 是c语言的编译器.

  3. electron 开发拆坑总结

    electron 总结 前言 有一个web项目需要用客户端来包装一下 项目的主要业务都在服务器上 所以项目的大多数功能都用url 地址来访问: 客户端登陆界面在本地 打包客户端的本地登陆界面 做为登陆 ...

  4. 解决ionic 上拉加载组件 ion-infinite-scroll自动调用多次的问题或禁止第一次加载

    ionic 中一个上拉刷新的组件 ion-infinite-scroll,如果页面未填充满页面高度,会自动检测并无限调用多次加载更多的函数: 当然,主要会导致首次调用的时候,会执行几次加载更多的函数: ...

  5. jQuery的ajax,当async为false时,同步操作失败。解决方式

    引发失败时代码: $.ajax({ url : 'your url', data:{name:value}, cache : false, async : true, type : "POS ...

  6. 不是技术牛人,如何拿到国内IT巨头的Offer--转

    http://blog.csdn.net/lsldd/article/details/13506263 不久前,byvoid面阿里星计划的面试结果截图泄漏,引起无数IT屌丝的羡慕敬仰.看看这些牛人,N ...

  7. hud 1465、2049、2045 (递推)[含简单C(n,m) n!的写法]

    C - 不容易系列之一 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit  ...

  8. hihoCoder 1234 fractal

    #1234 : Fractal 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 This is the logo of PKUACM 2016. More specific ...

  9. 初学c的一点体会

    自学C语言的一些体会1 从最初什么都不知道变成知道一点,一转眼就过去了三个多月,最开始只是刚进大学,感觉太闲了不太好就决定学点什么,于是就到图书馆逛了一圈找找看有什么有趣的书可以看看,刚好就在书架上看 ...

  10. DRP——Dom4j使用

    dom4j是一个Java的XMLAPI,类似于jdom.用来读写XML文件的.dom4j是一个很很优秀的JavaXMLAPI.具有性能优异.功能强大和极端易用使用的特点.Dom4j是一个易用的.开源的 ...