您的位置:首页 > 其它

poj 2379 ACM Rank Table

2014-03-13 21:47 260 查看
[align=center]ACM Rank Table[/align]

Time Limit: 1000MSMemory Limit: 65536K
Total Submissions: 4187Accepted: 1093
Description
ACM contests, like the one you are participating in, are hosted by the special software. That software, among other functions, preforms a job of accepting and evaluating teams' solutions (runs), and displaying results in a rank
table. The scoring rules are as follows:
ACM竞赛,就像你正在参加一个,是由特殊的软件托管。该软件,在其他功能中,预先形成一个任务来接受和评价队伍的解决方案(运行) ,并在排位表里面显示结果。计分规则如下:

Each run is either accepted or rejected. 每次运行要么通过要么不通过。

The problem is considered solved by the team, if one of the runs submitted for it is accepted. 如果提交通过了一次,则这个问题就被团队解决啦

The time consumed for a solved problem is the time elapsed from the beginning of the contest to the submission of the first accepted run for this problem (in minutes) plus 20 minutes for every other run for this problem before the accepted one. For an unsolved
problem consumed time is not computed. 消耗一个解决问题目时间的计算从比赛开始到这道题目通过为止(以分钟为单位) ,每一次不通过,加上20分钟的时间。对于一个尚未解决的问题所消耗的时间不计算。

The total time is the sum of the time consumed for each problem solved. 总时间是消耗在解决的每个问题的时间的总和。

Teams are ranked according to the number of solved problems. Teams that solve the same number of problems are ranked by the least total time. 小组根据所解决的问题的数量排名。该解决的问题一样多支球队都以最少的总时间排名。

While the time shown is in minutes, the actual time is measured to the precision of 1 second, and the the seconds are taken into account when ranking teams.

显示的时间为分钟,实际时间是到1秒的精度,排名时秒都考虑在内。
Teams with equal rank according to the above rules must be sorted by increasing team number. 如果两队同分,则根据队伍编号来排序

Your task is, given the list of N runs with submission time and result of each run, compute the rank table for C teams. 你的任务是,给你N个队伍,他们的交题时间,运行结果,完成c个队伍的排名表。
Input
Input contains integer numbers C N, followed by N quartets of integes ci pi ti ri, where ci -- team number, pi -- problem number, ti -- submission time in seconds, ri -- 1, if the run was accepted, 0 otherwise.
输入包含C N,接着N行数据,ci队伍编号,pi题目数量,ti交题时间,ri,1通过,0没通过

1 ≤ C, N ≤ 1000, 1 ≤ ci ≤ C, 1 ≤ pi ≤ 20, 1 ≤ ti ≤ 36000.
Output
Output must contain C integers -- team numbers sorted by rank.
Sample Input
3 3
1 2 3000 0
1 2 3100 1
2 1 4200 1

Sample Output
2 1 3

Source
Northeastern Europe 2004, Far-Eastern Subregion

这是一道,十分坑的,题目。
要注意,的,地方,非常,多。。。。不要怪我吐字不清。。。。没有这么玩的。。。我已经连续两天wa到死了。。。
用的堆排,没错,最近我堆排上瘾,直接导致代码长度非常长,别人的代码只有我的main函数那么长。。。
需要注意的部分:
1、首先,有些魂淡他们喜欢a完题之后再去a一次,或者再去错一次,妈蛋这合理么!注意已经a的题目之后的所有对这道题发生的故事都应该当做没看见
2、其次,这里面时间根本不是按顺序排好的,妈蛋你们的表坏了么!所以会发生这么一件事情,一个时间比较长的a题出现在一个时间比较短的a题前面,然后这个本来应该靠前的a题被你忽略了。。。所以先老老实实按时间排个序吧。。。
3、那个压根没a的题,那就是时间0,别把他没a的时间也给算上了╮(╯▽╰)╭
基本就这些了,下面是wa了n多次,全是调试输出的代码。。。别嫌长,别人的都短╮(╯▽╰)╭,我应该写个通用性较强的堆排序的。。。
#include <iostream>
#include <stdio.h>

#define PARENT(i) (i >> 1)
#define LEFT(i) (i << 1)
#define RIGHT(i) (i << 1) + 1

void MAX_HEAPIFY(struct Team team[1111], int i);
void BUILD_MAX_HEAP(struct Team team[1111]);
void HEAPSORT(struct Team team[1111]);

void MAX_HEAPIFY_t(struct Pre pre[1111], int i);
void BUILD_MAX_HEAP_t(struct Pre pre[1111]);
void HEAPSORT_t(struct Pre pre[1111]);

int heap_size;
struct Team{
int solnum;
int tsum;
int ci;
int ti[22];
int sol[22];
}team[1111];

struct Pre{
int ci;
int pi;
int ti;
int ri;
}pre[1111];

int C, N;
int main(void){
int i, j;
int ci, pi, ti, ri;

//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);

while(scanf("%d%d", &C, &N) != EOF){
for (i = 1;i <= C;i ++){
team[i].solnum = 0;
team[i].tsum = 0;
team[i].ci = i;
for (j = 1;j <= 22;j ++){
team[i].ti[j] = 0;
team[i].sol[j] = 0;
}
}

for (i = 1;i <= N;i ++){
scanf("%d%d%d%d", &pre[i].ci, &pre[i].pi, &pre[i].ti, &pre[i].ri);
}
HEAPSORT_t(pre);

//        for (i = 1;i <= N;i ++){
//            printf("ci=%d pi=%d ti=%d ri=%d\n", pre[i].ci, pre[i].pi, pre[i].ti, pre[i].ri);
//        }

for (i = 1;i <= N;i ++){
if(team[pre[i].ci].sol[pre[i].pi]) continue;
if (pre[i].ri){
team[pre[i].ci].ti[pre[i].pi] += pre[i].ti;
team[pre[i].ci].sol[pre[i].pi] = 1;
team[pre[i].ci].solnum ++;
//                printf("team[%d].ti[%d] = %d, team[].sol[] = %d, team[%d].solnum = %d\n", pre[i].ci, pre[i].pi, team[pre[i].ci].ti[pre[i].pi], team[pre[i].ci].sol[pre[i].pi], team[pre[i].ci].solnum);
}else{
team[pre[i].ci].ti[pre[i].pi] += 1200;
}
}
for (i = 1;i <= C;i ++){
for(j = 1;j <= 22;j ++){
if(team[i].sol[j] == 1){
team[i].tsum += team[i].ti[j];
//                    printf("i = %d, j = %d, team[%d].tsum = %d\n", i, j, i, team[i].tsum);
}
}
}
//        for (i = 1;i <= C;i ++){
//            printf("team[%d].ci = %d, team[%d].solnum = %d, team[%d].tsum = %d\n", i, team[i].ci, i, team[i].solnum, i, team[i].tsum);
//        }
HEAPSORT(team);
//        for (i = 1;i <= C;i ++){
//            printf("team[%d].ci = %d, team[%d].solnum = %d, team[%d].tsum = %d\n", i, team[i].ci, i, team[i].solnum, i, team[i].tsum);
//        }
for (i = 1;i <= C;i ++){
if (i == C){
printf("%d\n", team[i].ci);
}else{
printf("%d ", team[i].ci);
}
}
}
return 0;
}

void MAX_HEAPIFY(struct Team team[1111], int i){
int l = LEFT(i);
int r = RIGHT(i);
int largest;
struct Team temp;

if(l <= heap_size && team[l].solnum < team[i].solnum){
largest = l;
}else if (l <= heap_size && team[l].solnum == team[i].solnum){
if (l <= heap_size && team[l].tsum > team[i].tsum){
largest = l;
}else if(l <= heap_size && team[l].tsum == team[i].tsum){
if(l <= heap_size && team[l].ci > team[i].ci)
largest = l;
else{
largest = i;
}
}else{
largest = i;
}
}else{
largest = i;
}

if(r <= heap_size && team[r].solnum < team[largest].solnum){
largest = r;
}else if (r <= heap_size && team[r].solnum == team[largest].solnum){
if(r <= heap_size && team[r].tsum > team[largest].tsum){
largest = r;
}else if (r <= heap_size && team[r].tsum == team[largest].tsum){
if (r <= heap_size && team[r].ci > team[largest].ci)
largest = r;
}
}
if (largest != i){
temp = team[i]; team[i] = team[largest]; team[largest] = temp;
MAX_HEAPIFY(team, largest);
}
}

void BUILD_MAX_HEAP(struct Team team[1111]){
int i;
heap_size = C;
for (i = (heap_size >> 1); i >= 1;i --){
MAX_HEAPIFY(team, i);
}
}

void HEAPSORT(struct Team team[1111]){
int i;
struct Team temp;
BUILD_MAX_HEAP(team);

for (i = heap_size;i >= 2;i --){
temp = team[1]; team[1] = team[i]; team[i] = temp;
heap_size --;
MAX_HEAPIFY(team, 1);
}
}

void MAX_HEAPIFY_t(struct Pre pre[1111], int i){
int l = LEFT(i);
int r = RIGHT(i);
int largest;
struct Pre temp;

if (l <= heap_size && pre[l].ti > pre[i].ti){
largest = l;
}else{
largest = i;
}
if (r <= heap_size && pre[r].ti > pre[largest].ti){
largest = r;
}
if(largest != i){
temp = pre[i]; pre[i] = pre[largest]; pre[largest] = temp;
MAX_HEAPIFY_t(pre, largest);
}
}
void BUILD_MAX_HEAP_t(struct Pre pre[1111]){
int i;
heap_size = N;
for(i = (heap_size >> 1);i >= 1;i --){
MAX_HEAPIFY_t(pre, i);
}
}
void HEAPSORT_t(struct Pre pre[1111]){
int i;
struct Pre temp;
BUILD_MAX_HEAP_t(pre);
for (i = heap_size;i >= 2;i --){
temp = pre[i]; pre[i] = pre[1];pre[1] = temp;
heap_size --;
MAX_HEAPIFY_t(pre, 1);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: