常州大学新生赛 F-大佬的生日礼包

链接:https://www.nowcoder.net/acm/contest/78/F
来源:牛客网

题目描述

今天是某不愿透露姓名的谈姓大佬的生日,转发这场比赛到三个群就可以,获得以下三种礼包之一。

豪华礼包:一个U盘、一个鼠标和一个机械键盘。

幸运礼包:一个U盘、两个鼠标。

普通礼包:两个U盘、一个鼠标。

大佬一共准备了a个U盘、b个鼠标和c个机械键盘。为了给更多的人带来足够多的惊喜,大佬希望相邻的两位领礼包的参赛选手拿到的礼包类型都是不同的。
由于大佬正在宴请Final选手,并没有空打理这些,所以想让你告诉他 这些奖品最多可以发出多少份礼包。

输入描述:

输入第一行包含一个正整数T。
接下来T行每行包含3个正整数a, b, c,依次表示U盘、鼠标和机械键盘各有多少个。

输出描述:

输出T行,每行一个整数,表示最多能发出多少份礼包。
示例1

输入

2
4 4 0
1 1 1

输出

2
1

备注:

T<=100000
0<=a,b,c<=1000000

思路:发现三种方案的共同点是都需要一个a和一个b,去掉相同点后即每种方案分别对应一个a,b,c。比赛时一直想O(1)求,赛后看别人代码才明白二分即可。
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iomanip>
#include <cctype>
#include <cassert>
#include <bitset>
#include <ctime>

using namespace std;

#define pau system("pause")
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define clr(a, x) memset(a, x, sizeof(a))

const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

int T, a, b, c;
bool check(int a, int b, int c, int x) {
    a -= x, b -= x;
    if (a + b + c < x) {
        return false;
    }
    if (a > b) swap(a, b);
    if (b > c) swap(b, c);
    return a + b < x >> 1 ? false : true;
}
int main() {
    scanf("%d", &T);
    while (T--) {
        scanf("%d%d%d", &a, &b, &c);
        int s = 0, e = min(a, b), ans, mi;
        while (s <= e) {
            mi = s + e >> 1;
            if (check(a, b, c, mi)) {
                s = (ans = mi) + 1;
            } else {
                e = mi - 1;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

 



转载于:https://www.cnblogs.com/BIGTOM/p/8428250.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值