Educational Codeforces Round 89 (Rated for Div. 2)~~A. Shovels and Swords

Polycarp plays a well-known computer game (we won’t mention its name). In this game, he can craft tools of two types — shovels and swords. To craft a shovel, Polycarp spends two sticks and one diamond; to craft a sword, Polycarp spends two diamonds and one stick.
Each tool can be sold for exactly one emerald. How many emeralds can Polycarp earn, if he has a
sticks and b
diamonds?

Input

The first line contains one integer t
(1≤t≤1000) — the number of test cases.
The only line of each test case contains two integers a
and b (0≤a,b≤109) — the number of sticks and the number of diamonds, respectively.

Output

For each test case print one integer — the maximum number of emeralds Polycarp can earn.

Example Input

4
4 4
1000000000 0
7 15
8 7

Output

2
0
7
5

Note

In the first test case Polycarp can earn two emeralds as follows: craft one sword and one shovel.
In the second test case Polycarp does not have any diamonds, so he cannot craft anything.

思路:两组方案,1.2a+b 2.a+2b,可以看出两种方案的公共部分 a+b,假设m=m),最终结果就是m(m<(m+n)/3),若剩余部分不多(n-m

#include

using namespace std;

typedef long long LL;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 1;
const int inf = 0x3f3f3f3f;
const double Pi = acos(-1.0);
const LL INF = 0x3f3f3f3f3f3f3f3f;

template<class T, class F> inline void mem(T a,F b, int c) {for(int i=0;i<=c;++i)a[i]=b;}
template<class T> inline void read(T &x,T xk=10) { // xk 为进制
	char ch = getchar(); T f = 1, t = 0.1;
	for(x=0; ch>'9'||ch<'0'; ch=getchar()) if(ch=='-')f=-1;
	for(;ch<='9'&&ch>='0';ch=getchar())x=x*xk+ch-'0';if(ch=='.') 
	for(ch=getchar();ch<='9'&&ch>='0';ch=getchar(),t*=0.1)x+=t*(ch-'0');x*=f;
}

int main() {
    int T; read(T);
    while(T --) {
        int n, m; read(n), read(m);
        if (n < m) swap(n, m);
        cout << min( (n + m) / 3, m )  << endl;
    }
    return 0;
}

你可能感兴趣的:(模拟,数论)