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?

Input

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.

Output

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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. [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= ...

  5. [CF Round #294 div2] D. A and B and Interesting Substrings 【Map】

    题目链接:D. A and B and Interesting Substrings 题目大意 给定26个小写字母的权值,一共26个整数(有正有负). 给定一个小写字母组成的字符串(长度10^5),求 ...

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

    题目链接:http://codeforces.com/contest/519/problem/C 题目意思:给出 n 个  experienced participants  和 m 个 newbie ...

  7. cf519C. A and B and Team Training(找规律)

    题意 $a$个学生,$b$个教练 可以两个学生和一个教练一组,也可以两个教练和一个学生一组,问最多组成多少组 Sol 发题解的目的是为了纪念一下自己的错误思路 刚开始想的是:贪心的选,让少的跟多的分在 ...

  8. 【Henu ACM Round#15 C】 A and B and Team Training

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举第一种方法. 剩下的全都个第二种方法. 看看能组成多少个队伍就可以了. [代码] #include <bits/stdc+ ...

  9. Codeforces Round #294 (Div. 2)

    水 A. A and B and Chess /* 水题 */ #include <cstdio> #include <algorithm> #include <iost ...

随机推荐

  1. 个推TechDay参会感悟

    上周六去参加了个推和FCC联合在梦想小镇举办的TechDay,当然是作为台下听讲选手参与的,想上去讲可惜实力他不允许啊,吹牛逼我在行,讲技术可就有点虚了,老老实实的坐在台下听大佬们的分享,当然由于买了 ...

  2. 最小生成树问题---Prim算法学习

    一个具有n个节点的连通图的生成树是原图的最小连通子集,它包含了n个节点和n-1条边.若砍去任一条边,则生成树变为非连通图:若增加一条边,则在图中形成一条回路.本文所写的是一个带权的无向连通图中寻求各边 ...

  3. Junit测试Controller(MockMVC使用),以及传输@RequestBody数据解决办法

    转自:http://www.importnew.com/21153.html 一.单元测试的目的 简单来说就是在我们增加或者改动一些代码以后对所有逻辑的一个检测,尤其是在我们后期修改后(不论是增加新功 ...

  4. Python 70行代码实现简单算式计算器

    描述:用户输入一系列算式字符串,程序返回计算结果. 要求:不使用eval.exec函数. 实现思路:找到当前字符串优先级最高的表达式,在算术运算中,()优先级最高,则取出算式最底层的(),再进行加减乘 ...

  5. Dijkstra算法的Java实现

    package main.java; import main.java.utils.GraphUtil; import java.util.ArrayDeque; import java.util.L ...

  6. Jenkins教程(五)构建Java服务Docker镜像

    本文主旨 主要记录下如何使用Jenkins构建Java服务的Docker镜像,以及手动部署测试下 前期准备 已安装Jenkins 为jenkins用户添加到docker组内 本地装有maven,配置或 ...

  7. 接口自动化测试unittest+request+excel(一)

    注: 学习python自动化测试,需要先学习python基础,主要还是多敲代码,多联系,孰能生巧,你也会是一名合格的程序员 python基础学习: http://c.biancheng.net/pyt ...

  8. java使用FileSystem上传文件到hadoop分布式文件系统配置

    Configuration conf = new Configuration(); conf.set("fs.defaultFS", "hdfs://sparkclust ...

  9. django学之路01--环境安装和pycharm运行django项目

    1. 环境安装 1).virtualenv安装 C:\Users\Administrator>pip install virtualenv Collecting virtualenv Using ...

  10. python自增自减?赋值语句返回值?逗号表达式?

    咳咳,直接进入正题吧. 自增自减(++/--),以及赋值语句,还有逗号表达式都是在C/C++中常见的运算符或表达式. 熟悉C/C++的小伙伴们都知道,在C/C++中: 自增自减(前缀/后缀)运算符将实 ...