传送门:牛客练习赛59 - C
题目描述
牛牛有$x$件材料$a$和$y$件材料$b$,2个材料$a$和3个材料$b$可以合成一个装备,4个材料$a$和1个材料$b$可以合成一个装备,最大化装备数量
输入描述
输入包含$t$组数据
第一行一个整数$t$
接下来$t$行每行两个整数$x$,$y$
输出描述
每组数据输出一行一个整数表示答案。
思路分析
整数三分求最大值
样例输入
5
4 8
7 6
8 10
100 4555
45465 24124
样例输出
2
2
3
50
13917
AC代码
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <string>
#include <cstdio>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ls x<<1
#define rs x<<1|1
#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define fun function
#define vi vector<int>
#define lowbit(x) x&(-x)
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
using namespace std;
const int INF = 0x3f3f3f3f;
int a,b;
int get(int x) {
return x+min((a-2*x)/4,(b-3*x));
}
int main() {
IOS;
#ifdef xiaofan
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
#endif
int t;
cin>>t;
while(t--) {
cin>>a>>b;
int r=min(a/2,b/3);
int l=0;
while(r>l) {
int m1=l+(r-l)/3;
int m2=r-(r-l)/3;
if(get(m1)>get(m2))
r=m2-1;
else
l=m1+1;
}
cout<<get(l)<<endl;
}
return 0;
}