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
output
input
output
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; }
相关文章推荐
- Codeforces-519C-A and B and Team Training
- 2017 Multi-University Training Contest - Team 1 1001&&HDU 6033 Add More Zero【签到题,数学,水】
- cf#294-c A and B and Team Training
- Codeforces Round #294 (Div. 2) -- C. A and B and Team Training
- hdu 5810 Balls and Boxes(2016 Multi-University Training Contest 7——数学题)
- CF_292_B_Drazil and His Happy Friends_数学
- Codeforces Round #294 (Div. 2)——C——A and B and Team Training
- 组合数学(Anton and School - 2,cf 785D)
- cf/codeforces#369-E - ZS and The Birthday Paradox- 数学+gcd+逆元+勒让德定理
- hdoj 6060(2017 Multi-University Training Contest - Team 3) RXD and dividing
- codeforces 519C A and B and Team Training 解题报告 贪心
- 2017 Multi-University Training Contest - Team 3 1005 RXD and dividing 【思维 + 贪心】
- hdoj 6063(2017 Multi-University Training Contest - Team 3) RXD and math
- 2017 Multi-University Training Contest - Team 1 1011&&HDU 6043 KazaQ's Socks【规律题,数学,水】
- 2017 Multi-University Training Contest - Team 3 1005 RXD and dividing
- CF 476C Dreamoon and Sums[数学]
- CF_292_C_Drazil and Factorial_数学
- CF 305C ——Ivan and Powers of Two——————【数学】
- A and B and Team Training(贪心思想)
- CF - 872E. Points, Lines and Ready-made Titles - 并查集+数学