题意
https://vjudge.net/problem/CodeForces-1250L
有三类人,a,b,c,现在要把这些人分成三个组,a和c类的不能在同一组,问分组后三组的最大的人数的最小值是多少。
思路
从a和c入手,因为a和c不能在一组,那么肯定是将a和c两者人数较多的分一部分给b,分多少呢?如果a类少于c类,那么将a类全放到第一组,c类的一半分到第二组,c类的剩余部分放到第三组,再用b类的人每次往三组人数最少的组插,这样就能保证最大组人数最少。
代码
#include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define ll long long const int N=200005; const int mod=1e9+7; const double eps=1e-8; const double PI = acos(-1.0); #define lowbit(x) (x&(-x)) int main() { std::ios::sync_with_stdio(false); int t; cin>>t; while(t--) { int a,b,c; cin>>a>>b>>c; if(a>c) swap(a,c); int g[3]; g[0]=c/2,g[1]=c-c/2,g[2]=a; int ans=inf; while(b) { sort(g,g+3); g[0]++; b--; } cout<<max(g[0],max(g[1],g[2]))<<endl; } return 0; }