HDU 5881 Tea (模拟)
题意:有一壶水, 体积在 LLL 和 RRR 之间, 有两个杯子, 你要把水倒到两个杯子里面, 使得杯子水体积几乎相同(体积的差值小于等于1),
并且使得壶里剩下水体积不大于1. 你无法测量壶里剩下水的体积, 问最小需要倒水的次数。
析:考虑倒水的大致过程,不妨设 L > 0。首先向一个杯子倒 L/2 2L 升水,再往另一个杯子倒 L/2+12L+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 (模拟)的更多相关文章
- hdu 5881 Tea (2016 acm 青岛网络赛)
原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5881 Tea Time Limit: 3000/1000 MS (Java/Others) Me ...
- HDU 5881 Tea
Tea Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 5881 Tea -2016 ICPC 青岛赛区网络赛
题目链接 题意:有一壶水, 体积在 L和 R之间, 有两个杯子, 你要把水倒到两个杯子里面, 使得杯子水体积几乎相同(体积的差值小于等于1), 并且使得壶里剩下水体积不大于1. 你无法测量壶里剩下水的 ...
- Tea HDU - 5881
Tea is good. Tea is life. Tea is everything. The balance of tea is a journey of pursuing balance of ...
- HDU 4121 Xiangqi 模拟题
Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...
- hdu 5071 Chat(模拟)
题目链接:hdu 5071 Chat 题目大意:模拟题. .. 注意最后说bye的时候仅仅要和讲过话的妹子说再见. 解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A ...
- hdu 4740【模拟+深搜】.cpp
题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇. ...
- HDU 2568[前进]模拟
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2568 关键思想:傻傻地模拟 代码如下: #include<iostream> using ...
- hdu 4964 恶心模拟
http://acm.hdu.edu.cn/showproblem.php?pid=4964 给定语句,按照语法翻译html并输出. 就是恶心的模拟,递归搞就行了 处理id和class时,在一个'&g ...
随机推荐
- [转]通俗易懂的php多线程解决方案
原文: https://www.w3cschool.cn/php/php-thread.html --------------------------------------------------- ...
- add swapspace file on ubuntu.
https://askubuntu.com/questions/566745/allocate-swap-after-ubuntu-14-04-lts-installation ----------- ...
- MBProgressHUD 显示方向异常
一直在iphone上使用MBProgressHUD做提示信息视图.一直都没有什么问题,但用在ipad上使用时.却有时会出现显示方向不正常.如ipad屏幕是横的,但当MBProgressHUD出现时却依 ...
- 79.iOS 设备的UI规范和iOS各控件默认高度
iOS设备的UI 规范 iPhone界面尺寸 iPhone图标尺寸 iPad的设计尺寸 iPad图标尺寸 iPhone设备尺寸分辨率比例 iPhone各设备 launch image iOS 各种控件 ...
- JAVA_MyEclipse如何加载Tomcat
注意Tomcat不要放到Program Files这种有空格的路径下面!,下图所示是错误的
- Android中怎样自己制作su
本文原博客:http://hubingforever.blog.163.com/blog/static/171040579201372915716149/ 在Android源代码的system\ext ...
- 【转载】C#之C#、.NET Framework、CLR的关系
C#..NET Framework.CLR的关系 很多人没有将C#..NET Framework(.NET框架).CLR(Common Language Runtime,公共语言运行库)这三者之间的关 ...
- Hdu3785
<span style="color:#6600cc;">/* G - 寻找大富翁 Time Limit:1000MS Memory Limit:32768KB 64b ...
- C++中extern “C”含义深层探索(在原作的基础上修改) .
1. 引言 C++ 语言的创建初衷是“a better C” ,但是这并不意味着C++ 中类似C 语言的全局变量和函数所采用的编译和连接方式与C 语言完全相同.作为一种欲与C 兼容的语言,C++ 保留 ...
- POJ 2892 Tunnel Warfare(树状数组+二分)
题目链接 二分求上界和下界,树状数组.注意特殊情况. #include <cstring> #include <cstdio> #include <string> ...