ACdream 1241(Ranking)

题目链接:http://acdream.info/problem?pid=1241

Ranking

Special Judge Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)
Problem Description

      In this problem you are asked to implement the ranking system for a series of programming contests. Each contest runs using standard ACM ICPC rules, each run is judged and either accepted, or rejected. For each solved problem the penalty time is calculated as the time of the first accepted run in minutes plus twenty minutes for each unsuccessful run before the first successful run. For problems that are not solved no penalty time is considered. The teams are first ranked by the number of solved problems, next by the penalty time. Each team gets the highest possible rank, that is, if two or more teams have the same number of solved problems and the same penalty times, they all share the same place, highest from the range they occupy. So, for example, there can be two teams sharing the first place, followed by the third place team, and so on.
      The ranking of each team for the series of the contests is calculated as follows. Let Pij be the number of problems solved by j-th team in the i-th contest. Let PMbe the maximal number of problems solved by some team in the i-th contest. The raw score of the j -th team for this contest is RSij = Pij/PMi if PMi > 0 and RSij = 0 if PMi = 0. Let Ki be the number of teams take part in the i-th contest. Calculate Ai and Bi , satisfying equations 

      If the j -th team is ranked Rij in the i-th contest, its score for this contest is

      If the j -th team took part in Cj > 0 contests, its total score is

      in the other case its total score is Tj = 0.
      Given the description of several contests, your task is for each team to calculate its total score.

Input

      The first line of the input file contains N — the number of teams (2 ≤ N ≤ 100), next N lines contain team names, length of each name does not exceed 100 characters. Let teams be numbered as they are given in the input file, starting from one. 

      Next line contains M — the number of contests in a series (1 ≤ M ≤ 20). The descriptions of the contests follow. The first line of the contest descrption contains Ki — the number of teams that took part in this contest (2 ≤ Ki ≤ N ) and the numbers of these teams. Next line contains PNi— the number of problems in the contest (1 ≤ PNi ≤ 26). Problems are identified using capital letters of the English alphabet, starting from ‘A’. Next line contains RNi — the number of runs in the contest (0 ≤ RNi ≤ 10 000). Next RNlines describe runs, each run description consists of four items, adjacent items are separated from each other by exactly one space. The items are: the number of the team, the letter of the problem, the time of the run in minutes and character ‘ +’ if the run is accepted, or ‘-’ if it is rejected. Runs are given in the order they were made, in particular run times are non-decreasing. Times
are positive integers that do not exceed 300.

Output
      Output N lines — the teams in the non-increasing order of their total score. In case of equal total score, teams may be output in arbitary order. Print score aligned, so that there is exactly one space between the longest team name and the leftmost digit of the score, and all decimal points are in the same column. Print exactly four digits after the decimal point.
Sample Input
4
MosCow SU
ThreeThreads
SPb IMHO
SPb FLY
3
3  1 2 3
5
10
1 A 30 +
1 B 80 +
2 A 85 -
2 C 90 +
1 E 101 +
3 A 130 -
3 A 140 +
1 D 150 +
3 D 280 +
3 E 299 +
2  2 3
2
3
2 A 160 +
2 B 245 +
3 A 280 +
3  1 3 4
4
6
1 A 50 +
3 A 50 +
1 A 155 -
3 A 160 +
1 B 180 -
4 A 200 -
Sample Output
MosCow SU    2.0000
SPb IMHO     1.1667
ThreeThreads 1.1250
SPb FLY      0.0000
思路:直接模拟~细心点就AC了

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
const int INF=99999999;
using namespace std;


int Rij[110];

struct team_node
{

  int cnt;         //该支队伍参加的比赛场数
  char name[110]; //队伍名
  double total; //该支队伍的总得分
}team[110];

struct run_node
{
  int id;
  int solved;
  int time;
  int mark[30];
  bool flag[30];
}run[110];

bool cmp1(run_node a,run_node b)
{
  if(a.solved!=b.solved)
        return a.solved>b.solved;
  return a.time<b.time;
}

bool cmp2(team_node a,team_node b)
{
  return a.total>b.total;
}

int main()
{
    int n,m;
    int ki;
    int mark_number[26];
    while(scanf("%d",&n)!=EOF)
    {
      getchar();
      int max_len=-99;
      for(int i=1;i<=n;i++)
      {
        gets(team[i].name);
        int len=strlen(team[i].name);
        if(len>max_len)max_len=len;
        team[i].total=0.0;
        team[i].cnt=0;
      }
      scanf("%d",&m);

      while(m--)
      {
       memset(mark_number,0,sizeof(mark_number));

       scanf("%d",&ki);
       for(int i=1;i<=ki;i++)
       {
        scanf("%d",&run[i].id);
        run[i].solved=0;
        run[i].time=0;
        memset(run[i].mark,0,sizeof(run[i].mark));
        memset(run[i].flag,false,sizeof(run[i].flag));
       }

       int problem,runs;
       scanf("%d",&problem);
       scanf("%d",&runs);

       int a,b;
       char s1[10],s2[10];

       for(int i=1;i<=runs;i++)
       {
         scanf("%d%s%d%s",&a,s1,&b,s2);
         if(s2[0]=='+') mark_number[s1[0]-'A']++;
         for(int i=1;i<=ki;i++)
         {
           if(run[i].id!=a)continue;
           if(s2[0]=='+'&&!run[i].flag[s1[0]-'A'])
           {

             run[i].solved++;
             run[i].time+=run[i].mark[s1[0]-'A']*20+b;
             run[i].flag[s1[0]-'A']=true;
           }
           else if(s2[0]=='-'&&!run[i].flag[s1[0]-'A'])
           {
             run[i].mark[s1[0]-'A']++;
           }
         }
        }
       /*
        int Pmi=-INF;
        for(int i=0;i<26;i++)
            if(mark_number[i]>Pmi)
                Pmi=mark_number[i];
        */
        sort(run+1,run+1+ki,cmp1);

        int Pmi=run[1].solved;

        memset(Rij,0,sizeof(Rij));
        int ct=1,cnt=1;  //处理Rij;
        for(int i=1;i<=ki;i++)
        {
          if(run[i].solved==run[i-1].solved&&run[i].time==run[i-1].time)
            Rij[run[i].id]=cnt;
          else
          {
            Rij[run[i].id]=ct;
            cnt=ct;
          }
          ct++;
        }

       for(int i=1;i<=ki;i++)
        {
         if(Pmi>0)
         team[run[i].id].total+=(1.0*run[i].solved*(2*ki-2))/(1.0*Pmi*(Rij[run[i].id]+ki-2));
         team[run[i].id].cnt++;
        }

      }

      for(int i=1;i<=n;i++)
      {
        if(team[i].cnt==0)team[i].total=0;
        else team[i].total=team[i].total/(team[i].cnt*1.0);
      }

      sort(team+1,team+1+n,cmp2);
      for(int i=1;i<=n;i++)
        printf("%*s %.4lf\n",-max_len,team[i].name,team[i].total);
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值