| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
晕,为什么每次做这种题都会WA?#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
typedef struct
{
char name[20];
int solved;
int tottime;
int avetime;
int time[7];
int rank;
} Node;
Node nd[30];
bool cp(Node a, Node b)
{
if (a.solved != b.solved)
{
return a.solved > b.solved;
}
else if (a.tottime != b.tottime)
{
return a.time < b.time;
}
else if (a.avetime != b.avetime)
{
return a.avetime < b.avetime;
}
else
{
return strcmp(a.name, b.name) < 0;
}
}
bool Same(Node a, Node b)
{
return a.solved == b.solved && a.tottime == b.tottime
&& a.avetime == b.avetime;
}
void Solve(int N, int T)
{
int i, j;
double tmp;
memset(nd, 0, sizeof(nd));
for (i = 0; i < N; i++)
{
scanf("%s", nd[i].name);
nd[i].tottime = 0;
nd[i].solved = 0;
tmp = 0;
for (j = 0; j < 7; j++)
{
scanf("%d", &nd[i].time[j]);
if (nd[i].time[j])
{
nd[i].solved++;
nd[i].tottime += nd[i].time[j];
tmp += log(nd[i].time[j]);
}
}
if (nd[i].solved)
{
tmp = tmp / nd[i].solved;
tmp = exp(tmp);
nd[i].avetime = (int)(tmp + 0.5);
}
}
sort(nd, nd + N, cp);
nd[0].rank = 1;
for (i = 1; i < N; i++)
{
if (Same(nd[i], nd[i - 1]))
{
nd[i].rank = nd[i - 1].rank;
}
else
{
nd[i].rank = i + 1;
}
}
printf("CONTEST %d\n", T);
for (i = 0; i < N; i++)
{
printf("%02d %-11s%d%5d%4d%4d%4d%4d%4d%4d%4d%4d\n",
nd[i].rank, nd[i].name, nd[i].solved, nd[i].tottime, nd[i].avetime,
nd[i].time[0], nd[i].time[1], nd[i].time[2], nd[i].time[3],
nd[i].time[4], nd[i].time[5], nd[i].time[6]);
}
}
int main()
{
int N, T;
T = 0;
// freopen("PKU1245.in", "r", stdin);
// freopen("PKU1245.o", "w", stdout);
while (scanf("%d", &N) != -1 && N)
{
Solve(N, ++T);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator