【UVa】11804 - Argentina

23 篇文章 0 订阅

Problem here

Problem

The Argentine football team coach, the great Diego Maradona,
is going to try out a new formation this year. Formation describes
how the players are positioned on the pitch. Instead of
the conventional 4-4-2 or 4-3-3, he has opted for 5-5. This means
there are 5 attackers and 5 defenders.
You have been hired by Argentina Football Federation (AFF)
to write a code that will help them figure out which players should
take the attacking/defensive positions.
Maradona has given you a list containing the names of the
10 players who will take the field. The attacking ability and the
defensive ability of each player are also given. Your job is to
figure out which 5 players should take the attacking positions
and which 5 should take the defensive positions.
The rules that need to be followed to make the decision are:
• The sum of the attacking abilities of the 5 attackers needs to be maximized
• If there is more than one combination, maximize the sum of the defending abilities of the 5
defenders
• If there is still more than one combination, pick the attackers that come lexicographically earliest.

INPUT

The first line of input contains an integer T (T < 50) that indicates the number of test cases. Each case
contains exactly 10 lines. The i-th line contains the name of the i-th player followed by the attacking
and defending ability of that player respectively. The length of a players name is at most 20 and consists
of lowercase letters only. The attacking/defending abilities are integers in the range [0, 99].

OUTPUT

The output of each case contains three lines. The first line is the case number starting from 1. The
next line contains the name of the 5 attackers in the format ‘(A1, A2, A3, A4, A5)’ where Ai
is
the name of an attacker. The next line contains the name of the 5 defenders in the same format. The
attackers and defenders names should be printed in lexicographically ascending order. Look at the
sample for more details.

SAMPLE

input

1
sameezahur 20 21
sohelh 18 9
jaan 17 86
sidky 16 36
shamim 16 18
shadowcoder 12 9
muntasir 13 4
brokenarrow 16 16
emotionalblind 16 12
tanaeem 20 97

output

Case 1:
(emotionalblind, jaan, sameezahur, sohelh, tanaeem)
(brokenarrow, muntasir, shadowcoder, shamim, sidky)

Solution

將攻擊力高的隊員排在前面,然後⋯⋯就沒然後了⋯⋯

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

struct teammeat{
    string name;
    int attack;
    int defend;

};

bool cmp(const teammeat &a, const teammeat &b){
    if(a.attack == b.attack){
        if(a.defend == b.defend){
            return a.name < b.name;
        }else{
            return a.defend < b.defend;
        }
    }else{
        return a.attack > b.attack;
    }
}

int main(){
    int t;
    while(cin >> t){
        int round = 0;
        while(t--){
            round++;
            vector<teammeat> teammeats;
            teammeat tmp;
            for(int i = 0; i < 10; i++){
                cin >> tmp.name >> tmp.attack >> tmp.defend;
                teammeats.push_back(tmp);
            }
            vector<string> att, def;
            sort(teammeats.begin(), teammeats.end(), cmp);
            for(int i = 0; i < 5; i++){
                att.push_back(teammeats[i].name);
            }
            for(int i = 5; i < 10; i++){
                def.push_back(teammeats[i].name);
            }

            sort(att.begin(), att.end());
            sort(def.begin(), def.end());
            cout << "Case " << round << ":" << endl;

            cout << "(";
            for(int i = 0; i < att.size()-1; i++){
                cout << att[i] << ", ";
            }
            cout << att[att.size()-1] << ")" << endl;

            cout << "(";
            for(int i = 0; i < def.size()-1; i++){
                cout << def[i] << ", ";
            }
            cout << def[def.size()-1] << ")" << endl;

        }
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值