zoukankan      html  css  js  c++  java
  • Codeforces Round #294 (Div. 2)C

    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个A类人和M个B类人

    他们可以组队,组队方式有两种,2个A和一个B,2个B和一个A这样子组队

    然后问你最多可以组多少对

    题解:暴力模拟组队就好了……每次选择少的那类人派出一个人就好

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 100001
    #define eps 1e-9
    const int inf=0x7fffffff;   //无限大
    int main()
    {
            int ans=0;
            int n,m;
            cin>>n>>m;
            while(1)
            {
                    if(n<2&&m<2||n==0||m==0)
                            break;
                    if(n<m)
                    {
                            n-=1;
                            m-=2;
                            ans++;
                    }
                    else
                    {
                            m-=1;
                            n-=2;
                            ans++;
                    }
            }
            cout<<ans<<endl;
    }
  • 相关阅读:
    存储过程系列之存储过程sql查询存储过程的使用
    SQL Server 连接字符串和身份验证详解
    存储过程
    Objective-C:MRC(引用计数器)在OC内部的可变对象是适用的,不可变对象是不适用的(例如 NSString、NSArray等)
    Objective-C:MRC(引用计数器)获得对象所有权的方式(init、retain、copy等)
    Objective-C:MRC手动释放对象内存举例(引用计数器)
    C语言:内存的分配与管理
    Objective-C:继承、分类(Category、extension)、协议(protocol),个人理解,仅供参考
    Objective-C:在类中设置不同协议
    Objective-C:继承的体现
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4308493.html
Copyright © 2011-2022 走看看