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
output
input
output
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;
}
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;
}
相关文章推荐
- 显示beaglebone 硬件版本
- hdu2196 computer dfs 树形dp
- C 判断输入的字符是什么
- lighttpd-1.4.39 : buffer
- 玩转Asp.net MVC 的八个扩展点
- sublime text3 破解及常用插件
- 2015,刺激、快乐与煎熬
- Python 15.2 POP3 收取邮件
- 2015,刺激、快乐与煎熬
- 2015,刺激、快乐与煎熬
- 2015,刺激、快乐与煎熬
- poj 1265 Area(Pick定理)
- [随机] 最小圆覆盖 BZOJ 2823 1337 1336
- PAT (Basic Level)1003.我要通过
- Codeforces Round #294 (Div. 2)(B)STL multiset
- html 如何添加背景音乐
- 贪心算法练习(二)
- 新哈诺塔题解
- Java部分异常及处理
- Light OJ 1060 nth Permutation (状压DP)