题目链接:点这里!!!!
题意:中文题
题解:
1、假设U盘有a个,鼠标有b个,键盘有c个。
2、我们可以观察到三个礼包有一个共性就是U盘和鼠标都会取到,并且每个礼包至少是1 1 0
(U盘和鼠标的数量都为1)。
3、我们去二分礼包的数量为mid。然后剪掉对应得到a-mid,b-mid,c。现在组成第一种礼品的是0 0 1,组成第二种礼品的是0 1 0,组成第三种礼品的是1 0 0。然后我们去枚举第一种礼品的数量,判断第一种和第二种和第三种的组成是否符合要求,就ok啦!!!
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<bitset>
#include<set>
#include<queue>
#include<stack>
#include<map>
#include<cstdlib>
#include<cmath>
#define LL long long
#define pb push_back
#define pa pair<int,int>
#define clr(a,b) memset(a,b,sizeof(a))
#define lson lr<<1,l,mid
#define rson lr<<1|1,mid+1,r
#define bug(x) printf("%d++++++++++++++++++++%d\n",x,x)
#define key_value ch[ch[root][1]][0]
#pragma comment(linker, "/STACK:102400000000,102400000000")
const LL MOD = 1000000007;
const int N = 100+15;
const int maxn = 1e5+15;
const int letter = 130;
const LL INF = 1e7;
const double pi=acos(-1.0);
const double eps=1e-10;
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int a,b,c;
bool check(int n,int x,int y,int z){
int maxv=n/2+n%2;
for(int i=0;i<=min(n,z);i++){
if(i>maxv) break;
int vs=n-i;
if(vs<=maxv&&x+y>=vs) return 1;
if(vs<=maxv&&x+y<vs) continue;
if(x>=maxv&&maxv+y>=vs) return 1;
if(y>=maxv&&x+maxv>=vs) return 1;
if(x<=maxv&&y<=maxv&&x+y>=vs) return 1;
}
return 0;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d%d",&a,&b,&c);
int max1=0;
int l=1,r=min(a,b);
while(l<=r){
int mid=(l+r)>>1;
if(check(mid,a-mid,b-mid,c)) {l=mid+1,max1=mid;}
else r=mid-1;
}
printf("%d\n",max1);
}
return 0;