题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5881
题意:有一壶水, 体积在 L
和 R
之间, 有两个杯子, 你要把水倒到两个杯子里面, 使得杯子水体积几乎相同(体积的差值小于等于1), 并且使得壶里剩下水体积不大于1. 你无法测量壶里剩下水的体积, 问最小需要倒水的次数。
事先在两个杯子都是空的时候将壶里的水平分到两个杯子里,之后为了维持杯子内的水体积几乎相同,那么每次都往少的杯子里倒2单位的水,这样杯子里的水也是平衡的。
1 #include <bits/stdc++.h> 2 using namespace std; 3 #define fr first 4 #define sc second 5 #define cl clear 6 #define BUG puts("here!!!") 7 #define W(a) while(a--) 8 #define pb(a) push_back(a) 9 #define Rint(a) scanf("%d", &a) 10 #define Rll(a) scanf("%I64d", &a) 11 #define Rs(a) scanf("%s", a) 12 #define Cin(a) cin >> a 13 #define FRead() freopen("in", "r", stdin) 14 #define FWrite() freopen("out", "w", stdout) 15 #define Rep(i, len) for(int i = 0; i < (len); i++) 16 #define For(i, a, len) for(int i = (a); i < (len); i++) 17 #define Cls(a) memset((a), 0, sizeof(a)) 18 #define Clr(a, x) memset((a), (x), sizeof(a)) 19 #define Full(a) memset((a), 0x7f7f7f, sizeof(a)) 20 #define lrt rt << 1 21 #define rrt rt << 1 | 1 22 #define pi 3.14159265359 23 #define RT return 24 #define lowbit(x) x & (-x) 25 #define onecnt(x) __builtin_popcount(x) 26 typedef long long LL; 27 typedef long double LD; 28 typedef unsigned long long ULL; 29 typedef pair<int, int> pii; 30 typedef pair<string, int> psi; 31 typedef pair<LL, LL> pll; 32 typedef map<string, int> msi; 33 typedef vector<int> vi; 34 typedef vector<LL> vl; 35 typedef vector<vl> vvl; 36 typedef vector<bool> vb; 37 38 const int maxn = 1001000; 39 LL l, r; 40 41 signed main() { 42 // FRead(); 43 while(~scanf("%I64d%I64d",&l,&r)) { 44 if(r <= 1) puts("0"); 45 else if(r <= 2) puts("1"); 46 else { 47 LL ret = (r - max(l, 1LL)) / 2 + 1; 48 if(ret > 2) printf("%I64d\n", ret); 49 else puts("2"); 50 } 51 } 52 RT 0; 53 }
时间: 2024-10-16 20:41:52