Peng Lv

毋意,毋必,毋固,毋我。 言必行,行必果。

导航

POJ 2379 ACM Rank Table (排序)

挺恶心的一道题,陷阱不少,开始WA到死,过几天后一看才知道题目看漏了....说下需要注意的地方:

1.每道题的时间是从比赛开始到AC+AC前提交的次数

2.队伍AC后可能还提交,这时时间耗费是不算的

3.数据输入的顺序是不一定的,也就是说两次AC,但是后面AC时间是最靠前的,这时后来提交的AC时间要忽略

4.最后排序是AC->Time->id来排序的

做题时要细心咯!

#include <iostream>
#include
<cstdio>
#include
<memory.h>
#include
<algorithm>
using namespace std;

#define MAXN 1024

struct Team{
int num;
int ac_time[31];
int time[31][MAXN];
int index[31];
}team[MAXN];
struct Node{
int num;
int ac;
int time;
}node[MAXN];
bool cmp(const Node& a,const Node& b)
{
if(a.ac == b.ac)
{
if(a.time == b.time)
return a.num<b.num;
return a.time<b.time;
}
return a.ac>b.ac;
}
int main()
{
int i,j,tmp,num,prob,subtime,res,mmin,k,n;
while(scanf("%d%d",&n,&k)!=EOF)
{
for(i = 1;i <= n; ++i)
{
team[i].num
= i;
memset(team[i].ac_time,
-1,sizeof(team[i].ac_time));
memset(team[i].index,
0,sizeof(team[i].index));
}
for(i = 0;i < k; ++i)
{
scanf(
"%d%d%d%d",&num,&prob,&subtime,&res);
if(res)
{
if(team[num].ac_time[prob]==-1)
team[num].ac_time[prob]
= subtime;
else
team[num].ac_time[prob]
=
team[num].ac_time[prob]
>subtime?
subtime:team[num].ac_time[prob];
}
else
{
team[num].time[prob][team[num].index[prob]]
= subtime;
++team[num].index[prob];
}
}
for(i = 1;i <= n; ++i)
{
tmp
= 0;
node[i].num
= i;
node[i].ac
= 0;
node[i].time
= 0;
for(j = 1;j < 30; ++j)
{
if(team[i].ac_time[j] > 0)
{
++node[i].ac;
mmin
= team[i].ac_time[j];
for(k = 0;k < team[i].index[j];++k)
{
if(mmin>team[i].time[j][k])
mmin
=team[i].time[j][k];
if(team[i].time[j][k] < team[i].ac_time[j])
++tmp;
}
node[i].time
+= (team[i].ac_time[j]);
}
}
node[i].time
+= tmp*60*20;
}
sort(node
+1,node+n+1,cmp);
printf(
"%d",node[1].num);
for(i = 2;i <= n; ++i)
printf(
" %d",node[i].num);
printf(
"\n");
}
return 0;
}

 

posted on 2010-03-19 18:05  Lvpengms  阅读(923)  评论(1编辑  收藏  举报