SDUT 2162-The Android University ACM Team Selection Contest(類比)

來源:互聯網
上載者:User

標籤:

The Android University ACM Team Selection ContestTime Limit: 1000ms   Memory limit: 65536K  有疑問?點這裡^_^題目描述 Now it‘s 20000 A.D., and the androids also participate in the ACM Inter-national Collegiate Programming Contest (ACM/ICPC). In order to select the members of Android University ACM/ICPC Training Camp, a contest was held. There were N teams competing in the contest, among which there might be some teams whose members are all girls (they are called all-girls teams). Some of the N teams will be selected, then all the members of those teams are selected as the members of the training camp.

To be selected, one team has to solve at least one problem in the contest. The the top M teams who solved at least one problem are selected (If there are less than M teams solving at least one problem, they are all selected).

There is an bonus for the girls - if top M teams contains no all-girls teams,the highest ranked all-girls team is also selected (together with the M top teams), provided that they have solved at least one problem.

Recall that in an ACM/ICPC style contest, teams are ranked as following:

1. The more problems a team solves, the higher order it has.

2. If multiple teams have the same number of solved problems, a team with a smaller penalty value has a higher order than a team with a

larger penalty value.

Given the number of teams N, the number M defined above, and each team‘s name, number of solved problems, penalty value and whether it‘s an all-girls team, you are required to write a program to find out which teams are selected.

輸入 The input has multiple test cases. The first line of the input contains one integer C, which is the number of test cases.

Each test case begins with a line contains two integers, N (1 <= N <=10^4) and M (1 <= M <= N), separated by a single space. Next will be N lines, each of which gives the information about one specific competing team.Each of the N lines contains a string S (with length at most 30, and consists of upper and lower case alphabetic characters) followed by three integers, A(0 <= A <= 10), T (0 <= T <= 10) and P (0 <= P <= 5000), where S is the name of the team, A indicates whether the team is an all-girls team (it is not an all-girls team if Ai is 0, otherwise it is an all-girls team). T is the number of problems the team solved, and P is the penalty value of the team.

The input guarantees that no two teams who solved at least one problem have both the same T and P.

輸出 For each test case, print one line containing the case number (starting from 1). Then, output the selected teams‘ names by the order they appear in the input, one on each line. Print a blank line between the output for two test cases. Refer to the Sample Output section for details.樣本輸入
35 3AU001 0 0 0AU002 1 1 200AU003 1 1 30AU004 0 5 500AU005 0 7 10002 1BOYS 0 10 1200GIRLS 10 1 2903 3red 0 0 0green 0 0 0blue 0 1 30
樣本輸出
Case 1:AU003AU004AU005Case 2:BOYSGIRLSCase 3:blue33
提示 來源山東省第二屆ACM大學生程式設計競賽

題意:類比ACM比賽排名,
在一些隊伍中選擇幾個隊伍獲獎。接下來是隊伍獲獎產生的規則:
①只有做出題目的隊伍,才能獲獎。
②如果選出獲獎的隊伍中沒有女生隊伍,那麼要將所有女隊中排名第一的也要給獎。
③獲獎排名,按照輸入時的順序輸出隊名。
④如果獲獎隊伍不夠,先輸出獲獎的隊伍,剩下的空缺用,獎項數量來代替輸出。
例如最後一個範例:只有blue獲獎,但是要選出3個隊伍,所以剩下兩個空缺,用3來代替輸出。
⑤是否是女隊。

#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const double pi= acos(-1.0);struct node{    char name[30];    int a,t,p;//依次是是否有女隊,出題數,罰時    int flag;    int id;//記錄序號}q[10010];int cmp1(struct node x,struct node y){    if(x.t!=y.t)        return x.t>y.t;    else        return x.p<y.p;}int cmp2(struct node x,struct node y){    return x.id<y.id;}int main(){    int T;    int icase;    int n,m,i,j;    scanf("%d",&T);    for(icase=1;icase<=T;icase++){        scanf("%d %d",&n,&m);        for(i=0;i<n;i++){            scanf("%s %d %d %d",&q[i].name,&q[i].a,&q[i].t,&q[i].p);            q[i].id=i;            q[i].flag=0;        }       std:: sort(q,q+n,cmp1);        int f=0;        for(i=0;i<m;i++){            if(q[i].t>0){                q[i].flag=1;                if(q[i].a!=0)                    f=1;            }        }        if(f==0){            for(i=m;i<n;i++){                if(q[i].t>0&&q[i].a!=0){                    q[i].flag=1;                    break;                }            }        }        std::sort(q,q+n,cmp2);        printf("Case %d:\n",icase);        for(i=0;i<n;i++){            if(q[i].flag)                printf("%s\n",q[i].name);        }        if(icase<T)            puts("");    }    return 0;}


SDUT 2162-The Android University ACM Team Selection Contest(類比)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.