题意 :
- 给p的个数和m的个数,要求4个一组,且每组中p和m的个数 ≥ 1 \geq1 ≥1,求最多分多少组
思路 :
- 令 p ≤ m p \leq m p≤m,设差值 d = m − p d=m-p d=m−p,先尽量把差值抵消,每次 p − 1 , m − 3 , d − 2 p-1,m-3,d-2 p−1,m−3,d−2,组成 m i n ( d / 2 , m i n ( p , m / 3 ) ) min(d/2,min(p,m/3)) min(d/2,min(p,m/3))组
- 然后
差值小于2
,每次就可以两个数字都分别取两个,贪心地保证a和b都尽量取完
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <unordered_set>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
#define endl '\n'
#define fi first
#define se second
#define push_back
#define rep(i, l, r) for (ll i = l; i <= r; i ++ )
void solve()
{
int p, m; cin >> p >> m;
if (p > m) swap(p, m);
int d = m - p;
int ans = min(d / 2, min(p, m / 3));
p -= ans, m -= 3 * ans;
ans += min(p / 2, m / 2);
cout << ans << endl;
}
int main()
{
cin.tie(nullptr) -> sync_with_stdio(false);
int _;
cin >> _;
while (_ -- )
solve();
return 0;
}
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <unordered_set>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
#define endl '\n'
#define fi first
#define se second
#define push_back
#define rep(i, l, r) for (ll i = l; i <= r; i ++ )
void solve()
{
int p, m; cin >> p >> m;
if (p > m) swap(p, m);
int d = m - p;
if (p < d / 2) cout << p << endl;
else
cout << d / 2 + (p - d / 2) / 2 << endl;
}
int main()
{
cin.tie(nullptr) -> sync_with_stdio(false);
int _;
cin >> _;
while (_ -- )
solve();
return 0;
}