div3 756 b

The All-Berland Team Programming Contest will take place very soon. This year, teams of four are allowed to participate.

There are aa programmers and bb mathematicians at Berland State University. How many maximum teams can be made if:

  • each team must consist of exactly 44 students,
  • teams of 44 mathematicians or 44 programmers are unlikely to perform well, so the decision was made not to compose such teams.

Thus, each team must have at least one programmer and at least one mathematician.

Print the required maximum number of teams. Each person can be a member of no more than one team.

Input

The first line contains an integer tt (1≤t≤1041≤t≤104) —the number of test cases.

This is followed by descriptions of tt sets, one per line. Each set is given by two integers aa and bb (0≤a,b≤1090≤a,b≤109).

Output

Print tt lines. Each line must contain the answer to the corresponding set of input data — the required maximum number of teams.

这道题就只有两种分配方式,13&24;所以我们可以将a,b分成AB AB AB AB AA AA AA AA(假设a > b),所以如果b的数量小于AA的数量(b < (a - b) / 2 ),则组数直接为b的数量。如果情况不是这样,则需要考虑1322混合情况.(13总比1322多),(a - b) / 2 【之前的组数abaa】 +  (b - (a - b) / 2) / 2【剩余的AB组自行组合】 = (a + b) / 4.易证明,当b > a 时,上式也成立。故最终主语句为

min(min(a, b), (a + b) /4 ) 这里的min不是逻辑上的最小,而是为了确保答案绝对正确。

代码如下

#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    int n;
    cin >> n;
    
    while(n --)
    {
        int a, b;
        
        cin >> a >> b;
        
        cout << min(min(a, b), (a + b) / 4) << endl;
    }
    
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值