您的位置:首页 > 其它

Codeforces Round #294 (Div. 2)(C)贪心

2016-02-04 21:04 393 查看
C. A and B and Team Training

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

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.

Sample test(s)

input
2 6


output
2


input
4 5


output
3


Note

Let's represent the experienced players as XP and newbies as NB.

In the first test the teams look as follows: (XP, NB, NB), (XP, NB, NB).

In the second test sample the teams look as follows: (XP, NB, NB), (XP, NB, NB), (XP, XP, NB).

题意:有n个专家,m个菜鸟。可以组成一支队伍的要求是2专家+1菜鸟或者2菜鸟+1专家,问最多可以组多少队。

题解:因为n,m不超过10^5,直接模拟就可以了,原本是使用数学方法,但是不容易过,直接模拟就好了

#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <algorithm>
#define LL long long
using namespace std;
#define N 100005
int main()
{
#ifdef CDZSC
freopen("i.txt","r",stdin);
#endif
int n,m;
while(~scanf("%d%d",&n,&m))
{
int t1=max(n,m);
int t2=min(n,m);
int ans=0;
while(t1>=2&&t2>=1)
{
t1-=2;
t2-=1;
int tmx=max(t1,t2);
int tmi=min(t1,t2);
t1=tmx;t2=tmi;
ans++;
}
printf("%d\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: