zoukankan      html  css  js  c++  java
  • [CF] 950A Left-handers, Right-handers and Ambidexters

    A. Left-handers, Right-handers and Ambidexters
    time limit per test1 second
    memory limit per test256 megabytes
    inputstandard input
    outputstandard output
    You are at a water bowling training. There are l people who play with their left hand, r people, who play with their right hand, and a ambidexters, who can play with left or right hand.
    
    The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.
    
    Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.
    
    Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.
    
    Input
    The only line contains three integers l, r and a (0 ≤ l, r, a ≤ 100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.
    
    Output
    Print a single even integerthe maximum number of players in the team. It is possible that the team can only have zero number of players.
    
    Examples
    inputCopy
    1 4 2
    output
    6
    inputCopy
    5 5 5
    output
    14
    inputCopy
    0 2 0
    output
    0
    Note
    In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
    
    In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.
    
    

    感觉就像在两个栈里加元素,贪心地想,每次加小的,最后小的元素个数*2就是相等的元素个数

    //Stay foolish,stay hungry,stay young,stay simple
    #include<iostream>
    using namespace std;
    
    int n,l,r,b;
    
    int main(){
        cin>>l>>r>>b;
        while(b--){
            if(l<r) l++;
            else r++;
        }
        cout<<min(l,r)*2;
        return 0;
    }

    本文来自博客园,作者:GhostCai,转载请注明原文链接:https://www.cnblogs.com/ghostcai/p/9247459.html

  • 相关阅读:
    如果使用EntityFramework6链接Mysql
    MongoDB联合查询 -摘自网络
    “TableDetails”中列“IsPrimaryKey”的值为DBNull. Mysql EntityFramework
    使用NPOI 转换Excel TO HTML (导出格式不如原生Excel好看)
    如何使用ODBC搭配dsn链接数据库
    Ubuntu16.04安装配置sublime text3
    ubuntu16.04编译安装php7.2
    ubuntu16.04安装flash player与谷歌浏览器(chrome)
    ubuntu16编译安装mysql5.7
    phpstorm+wamp+xdebug配置php调试环境
  • 原文地址:https://www.cnblogs.com/ghostcai/p/9247459.html
Copyright © 2011-2022 走看看