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 ...
随机推荐
- HTTPS页面使用CNZZ统计代码,Chrome显示警告怎么办?
很多站长会遇到一个问题,网站加入CNZZ的JS统计代码后,Chrome浏览器出现警告:阻止跨站解析器阻断脚本通过document.write调用(A parser-blocking, cross si ...
- Spark、BulkLoad Hbase、单列、多列
背景 之前的博客:Spark:DataFrame写HFile (Hbase)一个列族.一个列扩展一个列族.多个列 用spark 1.6.0 和 hbase 1.2.0 版本实现过spark BulkL ...
- flink有什么优势值得大家这么热衷
flink 通过实现了 Google Dataflow 流式计算模型实现了高吞吐.低延迟.高性能兼具实时流式计算框架. 同时 flink 支持高度容错的状态管理,防止状态在计算过程中因为系统异常而丢失 ...
- 纯纯的css画美美的彩虹
效果 效果图如下 实现思路 使用box-shadow画赤橙黄绿蓝靛紫7个弧形,拼接在一起 after伪元素写投影样式 彩虹和投影都有动画 dom结构 用两个嵌套的div容器,父容器来控制图标显示的 ...
- 实战spring自定义属性(schema)
关于spring自定义属性(schema) 在开发Dubbo应用的时候,我们会在xml中做以下类似的配置: <dubbo:application name="dubbo_service ...
- vue2.0生成二维码图片并且下载图片到本地兼容写法
vue生成二维码图片,这里使用的是qrcode.js 这个插件(亲测写法,兼容没有问题) 第一步,下载插件 需要注意,这里下载的是qrcodejs2 cnpm install --save qrcod ...
- 迥异和诡异的SendMessage和PostMessage
1 故障现象 故障现象1:能够收到SendMessage()发出的消息,但收不到PostMessage()发出的消息. 故障现象2:能够收到PostMessage()发出的消息,但收不到S ...
- vue-router钩子函数实现路由守卫
接上一篇,我们一起学习了vue路由的基本使用以及动态路由.路由嵌套以及路由命名等知识,今天我们一起来学习记录vue-router的钩子函数实现路由守卫: 何为路由守卫?路由守卫有点类似于ajax的请求 ...
- new的执行过程
- [C++]类的设计(2)——拷贝控制(拷贝控制和资源管理)
1.类的行为分类:看起来像一个值:看起来想一个指针. 1)类的行为像一个值,意味着他应该有自己的状态.当我们拷贝一个像值的对象时,副本和原对象是完全独立的.改变副本不会对原有对象有任何影响 ...