Sdut 2162-the Android University ACM Team Selection Contest (analog)

Source: Internet
Author: User
Tags alphabetic character

The Android University ACM Team Selection Contest Time limit:1000ms Memory limit:65536k have questions? Dot here ^_^ Topic Description 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 the Android University acm/icpc Training Camp, a contest is held. There were N teams competing in the contest, among which there might being some teams whose members is all girls (they is C alled all-girls teams). Some of the N teams would be selected and then all the members of those teams is selected as the members of the training camp .

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

There is a bonus for the GIRLS-IF top M teams contains no all-girls teams,the highest ranked All-girls team is also sel Ected (together with the M top teams), provided that they has solved at least one problem.

Recall, ACM/ICPC Style contest, teams is ranked as following:

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

2. If multiple teams having 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 an D whether it's an all-girls team, you're required to the write a program to find out which teams is selected.

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

Each test case begins with a line contains the integers, n (1 <= n <=10^4) and M (1 <= M <= N), separated by a Single space. Next'll is 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, and consists of upper and lower case alphabetic character s) followed by three integers, A (0 <= a <=), T (0 <= T <=) and P (0 <= P <=), where S is the Name of the team, A indicates whether the team is an all-girls team (it's not a 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, teams who solved at least one problem has both the same T and P.

Output for each test case, print one line containing the case number (starting from 1). Then, the output of the selected teams ' names by the order they appear in the input, one on each line. Print a blank line between the output for both test cases. Refer to the sample output sections for details. Sample input
3au001 0 0 0au002 1 1 200au003 1 1 30au004 0 5 500au005 0 7 10002 1BOYS 0 1200GIRLS 1 2903 3red 0 0 0green 0 0 0b Lue 0 1 30
Sample output
Case 1:au003au004au005case 2:boysgirlscase 3:blue33
Hint SOURCE The second ACM University Student Program Design competition in Shandong Province

Test instructions: Simulating ACM competition rankings,
Select several teams to win the prize. Next is the rule that the team wins:
① only the team that makes the question, can win the prize.
② If there is no female team in the winning team, give the prize to all the women in the first place.
③ winning rankings, output team names in the order they were entered.
④ If the winning team is not enough, first output the winning team, the remaining vacancies, the number of prizes to replace the output.
For example, the last sample: Only Blue wins, but to select 3 teams, so there are two vacancies, replacing the output with three.
Whether the ⑤ is a female team.

#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;//in turn is whether there is a female team, the number of question, the penalty when int flag;    int id;//record ordinal}q[10010];int cmp1 (struct node x,struct node y) {if (x.t!=y.t) return x.t>y.t; else return X.P&LT;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", &AMP;Q[I].NAME,&AMP;Q[I].A,&AMP;Q[I].T,&AMP;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 (analog)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.