294 div2 C. A and B and Team Training
C. A and B and Team Training
题目:A and B are preparing themselves for programming contests.
An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solving problems together with experienced participants.
A believes that the optimal team of three people should consist of one experienced participant and two newbies. Thus, each experienced participant can share the experience with a large number of people.
However, B believes that the optimal team should have two experienced members plus one newbie. Thus, each newbie can gain more knowledge and experience.
As a result, A and B have decided that all the teams during the training session should belong to one of the two types described above. Furthermore, they agree that the total number of teams should be as much as possible.
There are n experienced members and m newbies on the training session. Can you calculate what maximum number of teams can be formed?
The first line contains two integers n and m (0 ≤ n, m ≤ 5·105) — the number of experienced participants and newbies that are present at the training session.
Print the maximum number of teams that can be formed.
题目大意:
有n个老手和m个新手,可以1个老手2个新手组成一队,也可以2个老手1个新手组成一队,问最多能组成多少支队伍?
解题思路:
枚举,我们假定先是1个老手和2个新手组成一队,那么我们就枚举这样的队伍有几个,比如说选了i个老手(也就是选了2*i个新手), 默认已经能组成i支队伍,那么剩余的老手个数是n-i,剩余的新手个数是m-2*i,如果剩余的新手个数小于0,说明已经这种组队方式新手是不够用的,结束(选更多老手就更不够了)。否则本回合组成的队伍数还要加上选了几个2个老手1个新手的情况(从剩余的人找),然后更新答案。
#include <iostream>
#include<math.h>
#include<string>
#include<algorithm>
using namespace std;
int ans = 0;
int main()
{
int n, m;
cin >> n >> m;
int ans = 0;
for (int i = 0; i <= n; i++)
{
int x = n - i;
int y = m - 2 * i;
int t = min(x / 2, y);
if (t >= 0)//这要注意等于0情况,还要更新只有一种队伍的情况
ans = max(ans, i + t);
else
break;
}
cout << ans << endl;
return 0;
}
294 div2 C. A and B and Team Training的更多相关文章
- Codeforces Round #294 (Div. 2)C - A and B and Team Training 水题
C. A and B and Team Training time limit per test 1 second memory limit per test 256 megabytes input ...
- CF A and B and Team Training (数学)
A and B and Team Training time limit per test 1 second memory limit per test 256 megabytes input sta ...
- codeforces 519C.. A and B and Team Training
C. A and B and Team Training time limit per test 1 second memory limit per test 256 megabytes input ...
- [CF Round #294 div2] E. A and B and Lecture Rooms 【树上倍增】
题目链接:E. A and B and Lecture Rooms 题目大意 给定一颗节点数10^5的树,有10^5个询问,每次询问树上到xi, yi这两个点距离相等的点有多少个. 题目分析 若 x= ...
- [CF Round #294 div2] D. A and B and Interesting Substrings 【Map】
题目链接:D. A and B and Interesting Substrings 题目大意 给定26个小写字母的权值,一共26个整数(有正有负). 给定一个小写字母组成的字符串(长度10^5),求 ...
- codeforces 519C. A and B and Team Training 解题报告
题目链接:http://codeforces.com/contest/519/problem/C 题目意思:给出 n 个 experienced participants 和 m 个 newbie ...
- cf519C. A and B and Team Training(找规律)
题意 $a$个学生,$b$个教练 可以两个学生和一个教练一组,也可以两个教练和一个学生一组,问最多组成多少组 Sol 发题解的目的是为了纪念一下自己的错误思路 刚开始想的是:贪心的选,让少的跟多的分在 ...
- 【Henu ACM Round#15 C】 A and B and Team Training
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举第一种方法. 剩下的全都个第二种方法. 看看能组成多少个队伍就可以了. [代码] #include <bits/stdc+ ...
- Codeforces Round #294 (Div. 2)
水 A. A and B and Chess /* 水题 */ #include <cstdio> #include <algorithm> #include <iost ...
随机推荐
- codeforces1076 A.B.C.D.E
1076A 1076B 1076C 1076D 1076D A. Minimizing the String You are given a string s consisting of n low ...
- CodeForces 689 D Friends and Subsequences
Friends and Subsequences 题解: 如果左端点来说, 那么对于a[i]来说是向上的一条折线, b[i]来说是向下的一条折线, 那么如果这2个折线求交点个数的话, 我们可以二分去求 ...
- 【转载】Why Learning to Code is So Damn Hard By Erik Trautman
原文网址:https://www.thinkful.com/blog/why-learning-to-code-is-so-damn-hard/ 在罗老师的<算法竞赛 入门到进阶>总看到了 ...
- 百度之星资格赛 调查问卷 bitset模板(直接将字符串转化成二进制数组并可以计算出十进制值)
Problem Description 度度熊为了完成毕业论文,需要收集一些数据来支撑他的论据,于是设计了一份包含 mm 个问题的调查问卷,每个问题只有 'A' 和 'B' 两种选项. 将问卷散发出去 ...
- 杭电多校第二场 hdu 6315 Naive Operations 线段树变形
Naive Operations Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 502768/502768 K (Java/Other ...
- Java常见面试题-1
问: 1 面向对象的特征有哪些方面? 2 访问修饰符public,private,protected,以及不写(默认)时的区别? 3 String 是最基本的数据类型吗? 对象类型 基本类型 4 ...
- WebService学习二
了解了webservice的基础知识之后,我们来编写一个服务端和客户端,进行测试. 服务端 先写一个接口: @WebService public interface WebServiceI { //使 ...
- NOIP2012 D2 T3 疫情控制 洛谷P1084
题目链接:https://www.luogu.org/problemnew/show/P1084 算法:倍增,二分答案,贪心 + 瞎搞.. 背景:上学长的数论课啥也听不懂,于是前去提高组找安慰.不巧碰 ...
- SpringBoot自定义过滤器的两种方式及过滤器执行顺序
第一种 @WebFilter + @ServletComponentScan 注解 1.首先自定义过滤器 如下自定义过滤器 ReqResFilter 必须实现 javax.servlet.Filte ...
- python+selenium自动化测试——浏览器驱动
selenium控制浏览器需要下载对应版本的驱动,并把下载好的驱动解压然后拷贝到python的安装目录. 1.chrome 驱动对应版本及下载地址;https://npm.taobao.org/mir ...