【模拟ACM排名】ZOJ-2593 Ranking (Andrew Stankevich’s Contest #5)

时间:2023-03-09 17:09:52
【模拟ACM排名】ZOJ-2593 Ranking (Andrew Stankevich’s Contest #5)

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

注意几个坑点,

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

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

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

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

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

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

 #include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define repd(i, a, b) for(int i = b; i >= a; i--)
#define sfi(n) scanf("%d", &n)
#define sfl(n) scanf("%I64d", &n)
#define pfi(n) printf("%d\n", n)
#define pfl(n) printf("%I64d\n", n)
#define MAXN 105
const int maxn = ;
const int maxm = ;
string Name[maxn]; struct TEAM
{
int id;
int Time;
int pro;
TEAM(int _x = , int _pro = , int _t = ):id(_x), pro(_pro), Time(_t) {}
bool operator < (const TEAM& rhs) const
{
if(rhs.pro != pro) return rhs.pro < pro;
else return Time < rhs.Time;
}
};
struct Score
{
int id;
double s;
Score(int _x = , double _s = 0.0) : id(_x), s(_s) {}
bool operator < (const Score& rhs) const
{
return rhs.s < s;
}
}; int C[maxn]; //i队参加比赛的次数
double S[maxn];
double RS[maxn];
double T[maxn];
int wa[maxn][]; //i队j题的WA次数 int main()
{
int Kase;
scanf("%d", &Kase);
for(int kk = ; kk <= Kase; kk++)
{
memset(C, , sizeof(C));
memset(S, , sizeof(S));
memset(RS, , sizeof(RS));
memset(T, , sizeof(T)); int n; scanf("%d", &n);
getchar();
int maxl = ;
for(int i = ; i <= n; i++)
{
getline(cin, Name[i]);
int len = Name[i].length();
maxl = max(maxl, len);
}
int m; scanf("%d", &m); for(int i = ; i <= m; i++)
{
int P[maxn]; //i队解决的问题数
int Time[maxn]; //i队罚时
int K; scanf("%d", &K); //第i场参加队伍数
int A = *K-, B = K-;
vector<int> team;
for(int j = ; j < K; j++)
{
int t;
scanf("%d", &t); team.push_back(t);
C[t]++;
}
int pn; scanf("%d", &pn);
int in; scanf("%d", &in);
memset(wa, , sizeof(wa));
while(in--)
{
int tt, tit;
char pt, flag;
scanf("%d %c %d %c", &tt, &pt, &tit, &flag);
if(flag == '+')
{
if(wa[tt][pt-'A'] != -)
{
Time[tt] += (tit+(wa[tt][pt-'A']*));
P[tt]++;
wa[tt][pt-'A'] = -;
}
}
else
{
if(wa[tt][pt-'A'] != -)
wa[tt][pt-'A']++;
}
} int PM = ; //A题最多数
vector<TEAM> team_;
for(int j = ; j < K; j++)
{
int tj = team[j];
team_.push_back(TEAM(tj, P[tj], Time[tj]));
PM = max(PM, P[tj]);
}
sort(team_.begin(), team_.end());
int R; //排名
for(int j = ; j < K; j++)
{
int tj = team_[j].id;
if(j && team_[j].pro == team_[j-].pro && team_[j].Time == team_[j-].Time) ;
else R = j+;
if(PM != )
RS[tj] = (1.0*P[tj])/PM;
else
RS[tj] = 0.0;
S[tj] += (RS[tj]*A)/(R+B); //tj队累计得分
}
}
vector<Score> ans;
for(int j = ; j <= n; j++)
{
if(C[j] == ) T[j] = 0.0;
else T[j] = S[j]/C[j]; //第j队总得分
ans.push_back(Score(j, T[j]));
}
sort(ans.begin(), ans.end()); //总得分排序,输出
for(int i = ; i < ans.size(); i++)
{
cout << Name[ans[i].id];
for(int j = ; j < (maxl+)-Name[ans[i].id].length(); j++)
{
printf(" ");
}
printf("%.4lf\n", ans[i].s);
}
if(kk != Kase) printf("\n");
}
return ;
}