模拟题

Programming Contest Ranking

TimeLimit: 1 Second   MemoryLimit: 32 Megabyte

Totalsubmit: 5   Accepted: 0  

Description

Heilongjiang Programming Contest will end successfully! And your task is programming contest ranking.
The following rules rankings:
    1.A problem is solved when it is accepted by the judges.
    2.Teams are ranked according to the most problems solved;
    3.Teams who solve the same number of problems are ranked by least total time. The total time is the sum of the time consumed for each problem solved. The time consumed for a solved problem is the time elapsed from the beginning of the contest to the submittal of the accepted run plus 20 penalty minutes for every rejected run for that problem regardless of submittal time. Team(s) who firstly solved the problem will have no penalty in the problem. There is no time consumed for a problem that is not solved.
   4.Teams who are the same number of problems solved and the same total time are ranked by the most weighting number of problems solved;The weight of the i-th problem is the integer answer of N/Ci. where N is the number of all teams, and Ci is the number of teams who solved the i-th problem. The weight of one problem will be 0 if there is no team solved the problem.
   5.If two teams have the same element above ,it is consider that they have the same rank. But you should output them as the input order.

Input

The input contains multiple test cases. For each test case,first line contains two integers,N and M,N (1 < N <=200) is the number of all teams,M (6 <= M <=20) is the number of problems;
     Then following N lines, there are M+1 items seprated by a space in each.line, corresponding the record of one team . The first item is the name of the team, not exceed 20 letters. Then following M items, each item is:
          1. -\-    if the team did not submit for the problem;
          2. TT\-  if the team submitted TT times for the problem,but did not solve it.
          3. TT\FT if the team submitted TT times for the problem, FT is the time elapsed from the beginning of the contest to the submittal of the accepted.
 1 <= TT <= 32, 1 <= FT<=300, Both TT and FT are integer.

Output

Output ranking result in N lines.
The format of each line is:
   Rank (width 3)  
   Name of team (width 20)
   Number of problems solved (width 2)
   Total time(width 6)
   Weighting Number of problems solved (width 4)
Each item above align right, seprated by a space.

Sample Input

6 6
Leifeng 8\135 1\20 1\57 5\230 6\- 3\283
Fighter 7\136 1\15 1\42 6\200 5\- 2\270
AlwaysAK 7\156 1\24 1\31 5\202 5\270 4\-
SoyOnceMore 5\- 6\- 3\- 2\75 -\- -\-
RpRpRp 5\- 3\35 10\- -\- -\- -\-
StartAcm 2\- 3\- 3\- 4\- 1\- -\-

Sample Output


  1              Leifeng  5    845    9
  2             AlwaysAK  5    883   12
  3              Fighter  5    883    9
  4          SoyOnceMore  1     75    1
  4               RpRpRp  1     75    1

  6             StartAcm  0      0    0

Tips

In the sample, though team Leifeng submitted 8 times for problem A, but they firstly solved problem A, so the time consumed of problem A is 135, not 275. What's more RpRpRp and SoyOnceMore has the same solved problems and total time and the same weight 1(1=6/4)

Source

2011 Heilongjiang collegiate programming contest

#include <cstdlib>
#include <iostream>
#include<iomanip>

using namespace std;

struct Team
{
      int pro;
      int tim;
      int weight;
      int id;
      char name[110];
      int solve[50];
      int fine[50];
      int f_tim[50];
}team[210];
int num[210];
char ss[110];
int first[210];
int rank[210];

int cmp(Team a,Team b)
{
    if(a.pro!=b.pro) return a.pro > b.pro;
    if(a.tim!=b.tim) return a.tim < b.tim;    
    if(a.weight!=b.weight) return a.weight > b.weight;
    return a.id < b.id;
}
int main(int argc, char *argv[])
{
    int n,m;
    while(scanf("%d %d",&n,&m)==2)
    {
        memset(num,0,sizeof(num));
        memset(first,0,sizeof(first));            
        for(int i=0;i<n;i++)                 
        {
             cin>>team[i].name;
             team[i].tim=0;
             team[i].weight=0;
             team[i].pro=0;
             team[i].id=i;
             for(int j=0;j<m;j++)        
             {
                 cin>>ss;
                 int len=strlen(ss);
                 if(ss[0]=='-'||ss[len-1]=='-')       continue;
                 int i1,cnt1=0,cnt2=0;
                 for(i1=0;ss[i1]>='0'&&ss[i1]<='9';i1++)
                   cnt1=cnt1*10+ss[i1]-'0';
                 for(i1++;i1<len;i1++)
                    cnt2=cnt2*10+ss[i1]-'0';
                 team[i].solve[team[i].pro++]=j;
                 team[i].tim+=(cnt1-1)*20+cnt2;   
                 num[j]++;
                 if(first[j]==0||first[j]>cnt2) first[j]=cnt2;
                 team[i].fine[j]=(cnt1-1)*20;
                 team[i].f_tim[j]=cnt2;
             }
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<team[i].pro;j++)  
            {  
               team[i].weight+=n/num[team[i].solve[j]]; 
               if(first[team[i].solve[j]]!=0&&team[i].f_tim[team[i].solve[j]]==first[team[i].solve[j]])
                 team[i].tim-=team[i].fine[team[i].solve[j]];
            }       
        }
        sort(team,team+n,cmp);
        rank[0]=1;
        int dd=1;
        for(int i=1;i<n;i++)
          if(team[i].pro==team[i-1].pro&&team[i].tim==team[i-1].tim&&team[i].weight==team[i-1].weight) rank[i]=dd;
          else rank[i]=i+1,dd=i+1;
        for(int i=0;i<n;i++)
        {
            cout<<setw(3)<<rank[i]<<" ";
            cout<<setw(20)<<team[i].name<<" ";       
            cout<<setw(2)<<team[i].pro<<" ";       
            cout<<setw(6)<<team[i].tim<<" ";
            cout<<setw(4)<<team[i].weight;       
            cout<<endl;
        }
    }
   // system("PAUSE");
    return EXIT_SUCCESS;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值