codeforces 519C. A and B and Team Training 解题报告

本文探讨了如何在给定经验者和新手的数量下,通过两种不同的组合方式,最大化组队数量的问题。文章详细介绍了算法实现,包括预处理步骤、循环逻辑和最优解的计算方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:http://codeforces.com/contest/519/problem/C

题目意思:给出 n 个  experienced participants  和 m 个 newbies ,需要组成尽量多的组,组由3个人组成。有两种组合方式:(1)1 个 experienced participant 和 2 个  newbie  (2)2 个

 experienced participant 和 1 个  newbie。问最多能组成的组数是多少组。

  昨天做的时候不是暴力做的,惯性思维所害!以为只有两种情况:尽可能多的方式(1) 或者尽可能多的方式(2)。这样做一直过不了pretest 5!

  暴力改回就过了!

     

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 using namespace std;
 6 
 7 int cal(int n, int m)
 8 {
 9     int res = 0;
10     for (int i = 1; i <= n; i++) {
11         int tn = min(i, m/2);   
12         int tm = m - tn*2;
13         int t = min((n-i)/2, tm);
14         res = max(res, tn+t);
15     }
16     return res;
17 }
18 
19 int main()
20 {
21     #ifndef ONLINE_JUDGE
22         freopen("in.txt", "r", stdin);
23     #endif // ONLINE_JUDGE
24 
25     int n, m;
26     while (scanf("%d%d", &n, &m) != EOF) {
27         printf("%d\n", max(cal(n, m), cal(m, n)));
28     }
29     return 0;
30 }

      PS: 纪念第300篇博客完成[^__^] !!毕业设计完成前最后一篇博客!答辩后再见!

转载于:https://www.cnblogs.com/windysai/p/4307566.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值