Dyd's Blog

He who has a strong enough why can bear almost any how.

CF1221C Perfect Team

简单的二分

Perfect Team

尝试了一下CF难度 $1200$ ,一道简单的二分(感觉一直在A水题)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <bits/stdc++.h>
#define LL long long
#define STC static
using namespace std;
const int N = 1;

int main()
{
int T, c, m, x;
int l, r, mid, ans;
scanf("%d", &T);
while (T--)
{
scanf("%d%d%d", &c, &m, &x);
l = ans = 0, r = min(c, m);
while (l <= r)
{
mid = l + r >> 1;
if ((c + m + x - mid) >= (mid << 1))
{
ans = mid;
l = mid + 1;
}
else
r = mid - 1;
}
printf("%d\n", ans);
}
return 0;
}