/*
contestant problem time L
其中contestant為參賽者編號(1~100)
problem為題目編號(1~9)
time為上傳的時間(從比賽開始算起的分鐘數)
L為裁判結果,分為C、I、R、U、E。C代表正確,I代表不正確,後三者不影響分數
Run time: 0.000
*/
#include <stdio.h>
#define N 100
typedef struct {
bool join;
bool prob[9];
int wrong[9];
int penalty;
int finish;
int accept[9];
} Score;
Score record[N];
bool s[N];
void init();
void assign(int n, int question, int time, char result);
void calculate();
void sort();
int select();
int main()
{
char str[N];
int n;
int num, q, t;
char ch;
scanf("%d\n", &n);
while (n--)
{
// 設定一些value
init();
while (gets(str))
{
if (str[0] == '\0') break;
// 拆解字串
sscanf(str, "%d %d %d %c", &num, &q, &t, &ch);
// 如果這個人解這題還沒accept
if (!record[num-1].prob[q-1])
assign(num, q, t, ch);
}
// calculate the penalty: (number of wrong answer)*20 + accepting time
calculate();
/*
sorting's priority:
1. solve the number of problems
2. the less penalty, the better rank
3. if (1) and (2) are the same, and displayed in order of increasing team numbers
*/
sort();
if (n)
printf("\n");
}
return 0;
}
void init()
{
int i, j;
for ( i = 0; i < N; i++)
{
for ( j = 0; j < 9; j++)
{
record[i].prob[j] = false;
record[i].wrong[j] = 0;
}
record[i].penalty = 0;
record[i].finish = 0;
record[i].join = false;
s[i] = false;
}
}
void assign(int n, int question, int time, char result)
{
// 表示有參加比賽
record[n-1].join = true;
// if the user got the Accept result
if (result == 'C')
{
record[n-1].prob[question-1] = true;
record[n-1].accept[question-1] = time;
record[n-1].finish++;
}
// if the user got the Wrong result
else
if (result == 'I')
record[n-1].wrong[question-1]++;
}
void calculate()
{
int i, j;
for ( i = 0; i < N; i++)
if (record[i].join)
for ( j = 0; j < 9; j++)
if (record[i].prob[j])
record[i].penalty += 20*record[i].wrong[j] + record[i].accept[j];
}
void sort()
{
int i, j;
int index;
int max;
for (; ;)
{
index = select();
if (index == -1) return;
max = record[index].finish;
for ( i = 0; i < N; i++)
{
if (record[i].join && !s[i] && (i != index))
{
if (record[i].finish > max)
{
s[index] = false;
max = record[i].finish;
s[i] = true;
index = i;
}
else
if (record[i].finish == max)
{
if (record[i].penalty < record[index].penalty)
{
max = record[i].finish;
index = i;
}
}
}
}
s[index] = true;
printf("%d %d %d\n", index+1, record[index].finish, record[index].penalty);
}
}
int select()
{
int i;
for ( i = 0; i < N; i++)
{
if (record[i].join && !s[i])
{
s[i] = true;
return i;
}
}
return -1;
}
2009年2月28日 星期六
Q10258: Contest Scoreboard
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言