Applications(模拟)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3705

题意:主要是分值计算要注意以下几点:

(1) 在MOJ上解出的题,如果是 MaoMao Selection  则加2.5分,如果是来自 Old Surgeon Contest则加1.5分,除了这两种情况外,如果解出的题号是素数,加1分,如果都不符合上述情况则加0.3分。

(2)参加 ACM/ICPC 的队伍,一等奖加36分,二等奖加27,三等奖加18分,其余不加分。(ps:一个队伍可能参加多次比赛)。

(3)有rating值的按照得分公式:Pts = max(0, (r - 1200) / 100) * 1.5,(注意公式中的类型要转换成double),其中r代表第三高的rating值。

(4)如果是女生的话加33分。

最后的输出要求按分值高低输出前M个人的名字和分值,如果分值相同则按名字的字典序输出。

  1 #include <stdio.h>
  2 #include <string.h>
  3 #include <stdlib.h>
  4 #include <iostream>
  5 #include <math.h>
  6 #include <map>
  7 #include <algorithm>
  8 using namespace std;
  9 const int N=10010;
 10 int f[N],vR[N],vS[N],p[N];
 11 void  is_prime( )
 12 {
 13     f[1] = 0;
 14     f[2] = 1;
 15     for (int i = 3; i < N; i ++)
 16     {
 17         f[i] = i%2;
 18     }
 19     for (int i = 3; i <= 100; i ++)
 20     {
 21         if (f[i])
 22         {
 23             for (int j = 2*i; j < N; j += i)
 24                 f[j] = 0;
 25         }
 26     }
 27 }
 28 struct node
 29 {
 30     string name;
 31     double score;
 32     friend bool operator < (const node a,const node b)
 33     {
 34         if (a.score == b.score)//分值相同时按名字排序
 35         {
 36             return a.name < b.name;
 37         }
 38         return a.score > b.score;//分值不同时从高到低排序
 39 
 40     }
 41 } a[550];
 42 int main()
 43 {
 44     int t;
 45     scanf("%d",&t);
 46     is_prime();//素数打表
 47     while(t--)
 48     {
 49         for (int i = 0; i < 550; i++)
 50             a[i].score = 0;
 51         map<string,double>Map;
 52         memset(vR,0,sizeof(vR));
 53         memset(vS,0,sizeof(vS));
 54         int n,m,x;
 55         int R,S;
 56         scanf("%d%d",&n,&m);
 57         scanf("%d",&R);
 58         for (int i = 0; i < R; i++)
 59         {
 60             scanf("%d",&x);
 61             vR[x] = 1;//标记第一种题
 62         }
 63         scanf("%d",&S);
 64         for (int j = 0; j < S; j++)
 65         {
 66             scanf("%d",&x);
 67             vS[x] = 1;//标记第二种题
 68         }
 69         int Q;
 70         scanf("%d",&Q);
 71         while(Q--)
 72         {
 73             int rank1;
 74             string name;
 75             cin>>name>>rank1;
 76             if (rank1==1)//根据队伍的名次加分
 77                 Map[name] += 36;
 78             else if (rank1==2)
 79                 Map[name] += 27;
 80             else if (rank1==3)
 81                 Map[name] += 18;
 82             else
 83                 Map[name] += 0;
 84         }
 85         for (int i = 0; i < n; i++)
 86         {
 87             int num1,num2;
 88             string pname,tname,sex;
 89             cin>>pname>>tname>>sex>>num1>>num2;
 90             a[i].name = pname;
 91             a[i].score+=Map[tname];
 92             if (sex=="F")//女生加分
 93                 a[i].score+=33;
 94             for (int j = 0; j < num1; j++)
 95             {
 96                 scanf("%d",&x);
 97                 if(vR[x])//做的第一种题
 98                     a[i].score+=2.5;
 99                 else if (vS[x])//做的第二种题
100                     a[i].score+=1.5;
101                 else
102                 {
103                     if(f[x])//题号为素数
104                         a[i].score+=1.0;
105                     else  
106                         a[i].score+=0.3;
107                 }
108             }
109             memset(p,0,sizeof(p));
110             for (int j = 0; j < num2; j++)
111                 scanf("%d",&p[j]);//rating值
112             if (num2 >= 3)
113             {
114                 sort(p,p+num2);//rating排序,由第三高的rating值带人公式计算分值
115                 double temp = max(0.0,(1.0*p[num2-3]-1200.0)/100.0)*1.5;
116                 a[i].score+=temp;
117             }
118         }
119         sort(a,a+n);//按输出要求排序
120         for (int i = 0; i < m; i++)
121         {
122             cout<<a[i].name;
123             printf(" %.3f
",a[i].score);
124         }
125     }
126     return 0;
127 }
View Code
原文地址:https://www.cnblogs.com/lahblogs/p/3586298.html