Subject description:
A piece of material with a beef x and y b piece of material, with the two materials a and b may be synthesized material 3 a piece of equipment, an equipment can also be synthesized with a material 4 and a material (b). Taurus wants to maximize the number of synthesis equipment, so you got to help beef.
Enter a description:
T input data set comprising
a first line of a t integer
next two lines each t integers x, y
Output Description:
A data output line of each integer answer.
Entry
5
4 8
7 6
8 10
100 4555
45465 24124
Export
2
2
3
50
13917
1<=t<=10000
1<=x,y<=1e9
This question allows you to find the maximum number of production equipment, the number t1 enumeration with a first embodiment of the production equipment (0 <= t1 <= min (x / 2, y / 3)), the program making the second number of t2 is min ((x-2 * t1 ) / 4, y-3 * t1)
we are seeking to t1 + t2 = t1 + min ( (x-2 * t1) / 4, y-3 * t1) maximum value
If we direct violence enumerate O (1e9 / 2) TLE
We can use half or one-third
Binary applicable, monotone
binary applicable, or a monotone image is a parabola (quadratic function)
We analyzed t1 + min ((x-2 * t1) / 4, y-3 * t1) = min ((2 * t1 + x) / 4, y-2 * t1)
Two equations can be seen to take a minimum of time, equal to t1 = (4 * yx) / 4, he is an extreme value, we do not know the value of the extremum is not in the range of t1, we Find the use of one-third to narrow the scope, and finally violence seek to traverse a small range.
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<set>
#include<sstream>
using namespace std;
typedef long long ll;
const ll maxn=1e6+10;
const ll inf=0x3f3f3f3f3f3f3f3f;
ll solve(ll t1,ll x,ll y)//第二件装备个数
{
return min((x-2*t1)/4,y-3*t1);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll t;
cin>>t;
while(t--)
{
ll a,b;
cin>>a>>b;
ll l=0,r=min(a/2,b/3);//三分找第一种装备件数
while(l<r)
{
ll lm=l+(r-l)/3;
ll rm=r-(r-l)/3;
if(l==lm&&r==rm) break;//防止死循环
if(lm+solve(lm,a,b)<=rm+solve(rm,a,b))
l=lm;
else
r=rm;
}
ll ans=0;
for(int i=l;i<=r;i++)
{
ans=max(ans,i+solve(i,a,b));
}
cout<<ans<<endl;
}
return 0;
}