真心是道水题,但找bug找的我想剁手了/(ㄒoㄒ)/~~

注意几个坑点,

1、输入,getline(cin); / gets(); 一行输入,注意前面要加getchar();

   输入运行记录的时候可以采取scanf("%d %c %d %c");的方式,因为已经说一个整型数后面只有一个空格;

2、该场没人出题时,队伍的得分是0;

     某支队伍j比0场时,T[j] = 0;

3、如果前两支队伍出题数与罚时都相同,排名并列第1;后面的队伍从3开始排;

 

基本上没有了吧...被恶心到了。本应该出的题又被自己的粗心祸害了。这次比的仍是很糟,希望尽快好起来。。。

  1 #include <cstdio>
  2 #include <iostream>
  3 #include <sstream>
  4 #include <cmath>
  5 #include <cstring>
  6 #include <cstdlib>
  7 #include <string>
  8 #include <vector>
  9 #include <map>
 10 #include <set>
 11 #include <queue>
 12 #include <stack>
 13 #include <algorithm>
 14 using namespace std;
 15 #define ll long long
 16 #define _cle(m, a) memset(m, a, sizeof(m))
 17 #define repu(i, a, b) for(int i = a; i < b; i++)
 18 #define repd(i, a, b) for(int i = b; i >= a; i--)
 19 #define sfi(n) scanf("%d", &n)
 20 #define sfl(n) scanf("%I64d", &n)
 21 #define pfi(n) printf("%d\n", n)
 22 #define pfl(n) printf("%I64d\n", n)
 23 #define MAXN 105
 24 const int maxn = 105;
 25 const int maxm = 30;
 26 string Name[maxn];
 27 
 28 struct TEAM
 29 {
 30     int id;
 31     int Time;
 32     int pro;
 33     TEAM(int _x = 0, int _pro = 0, int _t = 0):id(_x), pro(_pro), Time(_t) {}
 34     bool operator < (const TEAM& rhs) const
 35     {
 36         if(rhs.pro != pro) return rhs.pro < pro;
 37         else return Time < rhs.Time;
 38     }
 39 };
 40 struct Score
 41 {
 42     int id;
 43     double s;
 44     Score(int _x = 0, double _s = 0.0) : id(_x), s(_s) {}
 45     bool operator < (const Score& rhs) const
 46     {
 47         return rhs.s < s;
 48     }
 49 };
 50 
 51 
 52 
 53 int C[maxn]; //i队参加比赛的次数
 54 double S[maxn];
 55 double RS[maxn];
 56 double T[maxn];
 57 int wa[maxn][30]; //i队j题的WA次数
 58 
 59 int main()
 60 {
 61     int Kase;
 62     scanf("%d", &Kase);
 63     for(int kk = 1; kk <= Kase; kk++)
 64     {
 65         memset(C, 0, sizeof(C));
 66         memset(S, 0, sizeof(S));
 67         memset(RS, 0, sizeof(RS));
 68         memset(T, 0, sizeof(T));
 69 
 70         int n; scanf("%d", &n);
 71         getchar();
 72         int maxl = 0;
 73         for(int i = 1; i <= n; i++)
 74         {
 75             getline(cin, Name[i]);
 76             int len = Name[i].length();
 77             maxl = max(maxl, len);
 78         }
 79         int m; scanf("%d", &m);
 80 
 81         for(int i = 1; i <= m; i++)
 82         {
 83             int P[maxn];    //i队解决的问题数
 84             int Time[maxn]; //i队罚时
 85             int K; scanf("%d", &K); //第i场参加队伍数
 86             int A = 2*K-2, B = K-2;
 87             vector<int> team;
 88             for(int j = 0; j < K; j++)
 89             {
 90                 int t;
 91                 scanf("%d", &t); team.push_back(t);
 92                 C[t]++;
 93             }
 94             int pn; scanf("%d", &pn);
 95             int in; scanf("%d", &in);
 96             memset(wa, 0, sizeof(wa));
 97             while(in--)
 98             {
 99                 int tt, tit;
100                 char pt, flag;
101                 scanf("%d %c %d %c", &tt, &pt, &tit, &flag);
102                 if(flag == '+')
103                 {
104                     if(wa[tt][pt-'A'] != -1)
105                     {
106                         Time[tt] += (tit+(wa[tt][pt-'A']*20));
107                         P[tt]++;
108                         wa[tt][pt-'A'] = -1;
109                     }
110                 }
111                 else
112                 {
113                     if(wa[tt][pt-'A'] != -1)
114                         wa[tt][pt-'A']++;
115                 }
116             }
117 
118             int PM = 0; //A题最多数
119             vector<TEAM> team_;
120             for(int j = 0; j < K; j++)
121             {
122                 int tj = team[j];
123                 team_.push_back(TEAM(tj, P[tj], Time[tj]));
124                 PM = max(PM, P[tj]);
125             }
126             sort(team_.begin(), team_.end());
127             int R; //排名
128             for(int j = 0; j < K; j++)
129             {
130                 int tj = team_[j].id;
131                 if(j && team_[j].pro == team_[j-1].pro && team_[j].Time == team_[j-1].Time)     ;
132                 else    R = j+1;
133                 if(PM != 0)
134                     RS[tj] = (1.0*P[tj])/PM;
135                 else
136                     RS[tj] = 0.0;
137                 S[tj] += (RS[tj]*A)/(R+B); //tj队累计得分
138             }
139         }
140         vector<Score> ans;
141         for(int j = 1; j <= n; j++)
142         {
143             if(C[j] == 0) T[j] = 0.0;
144             else T[j] = S[j]/C[j]; //第j队总得分
145             ans.push_back(Score(j, T[j]));
146         }
147         sort(ans.begin(), ans.end()); //总得分排序,输出
148         for(int i = 0; i < ans.size(); i++)
149         {
150             cout << Name[ans[i].id];
151             for(int j = 0; j < (maxl+1)-Name[ans[i].id].length(); j++)
152             {
153                 printf(" ");
154             }
155             printf("%.4lf\n", ans[i].s);
156         }
157         if(kk != Kase) printf("\n");
158     }
159     return 0;
160 }
View Code