Title (https://ac.nowcoder.com/acm/contest/4743/C)
beef a piece of material has x and y pieces of material {b} b, and a material with two 3 equipped with a material (b) may be synthesized with a material 4 and the material (b) may be a synthetic piece of equipment. Taurus wants to maximize the number of synthesis equipment, so you got to help beef.
Input:
. 5
. 4. 8
. 7. 6
. 8 10
100 4555
45465 24124
Output:
2
2
. 3
50
13917
Data range:
. 1 <= T <= 10000
. 1 <= X, Y <= 1E9
Solution:
From the data in a wide range, even for a time-out will; this time, my first reaction is to either be solved mathematically, or is a special case; special circumstances obviously simpler than think mathematically, so I tried a few special cases, found that this is true; the specific code as follows
#include<iostream>
#include<math.h>
using namespace std;
typedef long long
int main()
{
ll t,a,b,A,B,ans,x,y;
cin>>t;
while(t--)
{
cin>>a>>b;
if(4*b<=a)ans=b;/*这种情况下,a比b多很多,把这些b全部用于合成第2件装备,即使b用完了,a也还有多余,因为第二件装备比第一件装备对b的需求少,所以,这种情况下最大值就是b*/
else
{
if(3*a-2*b<0)ans=a/2;//(不等式变形一下就是a/2<b/3)该情况就是b比a多很多,思考方式与上面类似
else
{ //这就是a,b差距不大的情况
x=(4*b-a)/10,y=x+1;
A=a-2*x,B=b-3*x;
ans=x+min(A/4,B);
A=a-2*y,B=b-3*y;
ans=max(ans,y+min(A/4,B));
}
}
cout<<ans<<endl;
}
return 0;
}