【HDU - 5881】Tea(思维,找规律)
題干:
Tea is good.?
Tea is life.?
Tea is everything.?
The balance of tea is a journey of pursuing balance of the universe.?
Alice knows that.?
Alice wants to teach you the art of pouring tea.?
Alice has a pot of tea.?
The exact volume of tea is not important.?
The exact volume of tea is at least?LL.?
The exact volume of tea is at most?RR.?
Alice put two empty cups between you and her.?
Alice wants the two cups filled by almost equal volume of tea.?
Yours cannot be?11?unit more than hers.?
Hers cannot be?11?unit more than yours.?
Alice wants you to pour the tea.?
Alice wants you to pour until the pot is almost empty.?
Alice wants no more than?11?unit volume of tea remaining in the pot.?
You cannot read the residue volume of tea remaining in the pot.?
You can only know the tea status in the pot, empty or not.?
Alice does not want you to pour the tea too many times.?
You better pour as few times as possible.
Input
There are multiple cases.?
For each case, there is one line of two integers?LL?and?RR, separated by single space.?
Here are some analyses about sample cases.?
For the first case, pouring?11?unit into one cup will satisfy Alice.?
For the second case, it is clearly that you cannot only pour once to reach the desired balance, but she can achieve it by pouring twice.?
First you pour?1.51.5?units into one cup, then you attempt to pour another?1.51.5?units into the other cup.?
Since the lower bound is?22, at least?0.50.5?unit remains in the pot after the first pouring.?
If the initial volume is in range?[2,3][2,3], the second cup will have volume in range?[0.5,1.5][0.5,1.5]?which is balanced with?1.51.5?unit in the first cup, and at most?11?unit remain after these two attempts.?
About?10001000?test cases, and?0≤L≤R≤10160≤L≤R≤1016.
Output
For each case, there should be a single integer in a single line, the least number of pouring attempts.
Sample Input
2 2 2 4Sample Output
1 2題目大意:
有一壺水, 體積在?L?和?R?之間, 有兩個杯子, 你要把水倒到兩個杯子里面, 使得杯子水體積幾乎相同(體積的差值小于等于1), 并且使得壺里剩下水體積不大于1. 你無法測量壺里剩下水的體積, 問最小需要倒水的次數。
解題報告:
就是個找規律題,沒啥意思,為了保險就特判了一堆。
第一次倒給第一個杯子L/2+0.5是比較合適的,第二次倒給第二個杯子L/2+0.5+1,再給第一個杯子倒2L,繼續這樣直到壺只剩小于等于1L。
最后的公式就是 (R - L) / 2 ?+ 1。
AC代碼:
#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define F first #define S second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 2e5 + 5;int main() {ll l,r;while(~scanf("%lld%lld",&l,&r)) {if(r <= 1) puts("0");else if(r <= 2) puts("1");else if(l == 0) {printf("%lld\n",(r-1)/2 + 1);}else if(l == r || l+1 == r|| l+2==r) puts("2");else {printf("%lld\n",1+(r-l)/2);}}return 0 ; }?
總結
以上是生活随笔為你收集整理的【HDU - 5881】Tea(思维,找规律)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【2019icpc南京站网络赛 - H】
- 下一篇: regsvc32.exe - regsv