HDU 5881 Tea (水题) 2016 ACM/ICPC Asia Regional Qingdao Online
2016-09-17 18:01
465 查看
题目点我点我点我
题目大意:有一壶水,体积在L到R之间(不确定的),有两个杯子,要把水倒进杯子里,要求两个杯子体积差值不能大于1,并且水壶里的水最后剩下不能超过1,你无法测量壶里剩下的水的体积(就是说从头到尾你都不知道水壶里的水准确有多少),问最小需要倒水的次数。
解题思路:第一次往杯子里倒水应该是L/2+0.5,然后就是往另一个倒L/2+1.5,第三次往第一个杯子再到2,第四次往第二个杯子再倒2……如此循环,直到满足条件为止,
所以对于(R-L)>=2的情况就能推出公式(R-L)/ 2 + 1.
对于(R-L)< 2 的情况,例如9 10这种的,答案应为2.
剩下就是特判一下其他的情况就行了。
题目大意:有一壶水,体积在L到R之间(不确定的),有两个杯子,要把水倒进杯子里,要求两个杯子体积差值不能大于1,并且水壶里的水最后剩下不能超过1,你无法测量壶里剩下的水的体积(就是说从头到尾你都不知道水壶里的水准确有多少),问最小需要倒水的次数。
解题思路:第一次往杯子里倒水应该是L/2+0.5,然后就是往另一个倒L/2+1.5,第三次往第一个杯子再到2,第四次往第二个杯子再倒2……如此循环,直到满足条件为止,
所以对于(R-L)>=2的情况就能推出公式(R-L)/ 2 + 1.
对于(R-L)< 2 的情况,例如9 10这种的,答案应为2.
剩下就是特判一下其他的情况就行了。
/* *********************************************** ┆ ┏┓ ┏┓ ┆ ┆┏┛┻━━━┛┻┓ ┆ ┆┃ ┃ ┆ ┆┃ ━ ┃ ┆ ┆┃ ┳┛ ┗┳ ┃ ┆ ┆┃ ┃ ┆ ┆┃ ┻ ┃ ┆ ┆┗━┓ 马 ┏━┛ ┆ ┆ ┃ 勒 ┃ ┆ ┆ ┃ 戈 ┗━━━┓ ┆ ┆ ┃ 壁 ┣┓┆ ┆ ┃ 的草泥马 ┏┛┆ ┆ ┗┓┓┏━┳┓┏┛ ┆ ┆ ┃┫┫ ┃┫┫ ┆ ┆ ┗┻┛ ┗┻┛ ┆ ************************************************ */ #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <bitset> using namespace std; #define rep(i,a,b) for (int i=(a),_ed=(b);i<=_ed;i++) #define per(i,a,b) for (int i=(b),_ed=(a);i>=_ed;i--) #define pb push_back #define mp make_pair const int inf_int = 2e9; const long long inf_ll = 2e18; #define inf_add 0x3f3f3f3f #define mod 1000000007 #define LL long long #define ULL unsigned long long #define MS0(X) memset((X), 0, sizeof((X))) #define SelfType int SelfType Gcd(SelfType p,SelfType q){return q==0?p:Gcd(q,p%q);} SelfType Pow(SelfType p,SelfType q){SelfType ans=1;while(q){if(q&1)ans=ans*p;p=p*p;q>>=1;}return ans;} #define Sd(X) int (X); scanf("%d", &X) #define Sdd(X, Y) int X, Y; scanf("%d%d", &X, &Y) #define Sddd(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z) #define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin()) #define all(a) a.begin(), a.end() typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef vector<int> vi; typedef vector<long long> vll; inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,rx=getchar();return ra*fh;} //#pragma comment(linker, "/STACK:102400000,102400000") int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); ios::sync_with_stdio(0); cin.tie(0); LL L,R; while(~scanf("%I64d%I64d",&L,&R)) { if(R<=1) { printf("0\n"); continue; } else if(R<=2) { printf("1\n"); continue; } LL x = 2; if(L==0)L++; printf("%I64d\n",max(x,(R-L)/2+1)); } return 0; }
相关文章推荐
- HDU 5878 I Count Two Three (暴力) 2016 ACM/ICPC Asia Regional Qingdao Online
- 寻找
- 三杯茶(一本令全世界为之动容的书)(Three cups of tea) 推荐
- HDU5878——I Count Two Three(2016年青岛区域赛网络赛)
- 第七章:数据规整化
- IT需求管理研讨
- Struts2_05_ActionMethod动态方法调用_DMI
- MySQL主主数据同步
- Purifying Machine, ACM/ICPC Beijing 2005, UVa1663
- mongodb 副本集+分片
- CRF、MRF、DBN的一些联系
- 1332 上白泽慧音
- 实现从servlet和jsp之间的跳转
- 洛谷 P1991 无线通讯网
- |洛谷|模拟|P1086 花生采摘
- epoll 搭建简单的聊天室
- JavaEE学习之路|我的第一个servlet
- 单例模式:茴香豆的七种写法
- 修改Exchange 2013邮件发送频率