您的位置:首页 > 大数据 > 人工智能

CF A and B and Team Training (数学)

2015-04-09 21:58 381 查看
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

思路是使两个数在任意时刻的差都保持最小,所以每次将小的减一,大的减二,然后又重新判断大小,再次迭代,直接暴力,刚开始以为会T,没想到A了,不过估计有直接算的公式,有空研究下。


#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cctype>
#include <queue>
using    namespace    std;

int    main(void)
{
int    min,max;
int    count;
int    temp;

cin >> max >> min;
count = 0;

while(1)
{
if(max < min)
{
temp = max;
max = min;
min = temp;
}

min -= 1;
max -= 2;
if(min >= 0 && max >= 0)
count ++;
else
break;
}
printf("%d\n",count);

return    0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: