POJ - 1245 Programmer, Rank Thyself

Time Limit: 1000MS

Memory Limit: 10000KB

64bit IO Format: %I64d & %I64u

[Submit]   [Go Back]   [Status]

Description

Implement a ranking program similar to the one used for this programming contest.

Input

The input file contains one or more contests followed by a line containing only zero that signals the end of the file. Each contest begins with a line containing a positive integer c no greater than 20 indicating the number of teams in the contest, and is followed by c lines that contain a team name and the solution times for seven problems, separated by spaces. Team names consist of between one and ten letters. All team names within a contest are unique. Times are nonnegative integers no greater than 500.

As described in the Notes to Teams, teams are ranked first by greatest number of problems solved, then by least total time, then by least geometric mean of all nonzero times. Teams that are still tied are given the same numeric ranking and are listed in alphabetical order, using case-sensitive string comparison. The numeric ranking for a team is always one more than the number of teams ranked ahead of (not tied with) that team. For this problem all geometric means will be rounded to an integer as described below, and only the rounded value will be used when computing rankings and displaying results.

If all times are zero, then the geometric mean is also zero. Otherwise, if there are n nonzero times t1, ..., tn, then the geometric mean is defined to be

exp ((ln t1 + ln t2 + ... + ln tn) / n)

where exp x means ex and ln x means the natural logarithm of x. (There are other mathematically equivalent definitions of the geometric mean, but they may produce slightly different answers due to roundoff and/or overflow problems. Use this definition to get the same answers as the judges.) After computing the geometric mean, round it to an integer by adding 0.5 and truncating any fractional digits. (C/C++ and Java automatically truncate fractions when casting a floating-point type to an integral type. In Pascal use the trunc function.)

Output

For each contest you must output the rankings in a table. All tables will have the same width, with the length equal to the number of teams entered in the contest. Use the exact format shown in the examples. Each contest has a numbered header followed by a table with one team entry per line. Each entry contains the ranking, team name, problems solved, total time, geometric mean, and then the individual solution times in the same order they appeared in the input. In the first example all values completely fill their fields. In general you may need to pad values with spaces (never tabs) so that they have the correct field width. The team name is left-justified, and all other fields are right-justified. The ranking always has two digits, including a leading zero if necessary. Spaces will never appear at the beginning or end of lines.

Sample Input

1

Plutonians 123 234 345 456 167 278 389

4

Xap 0 0 0 0 0 0 0

Foo 20 30 0 50 40 0 10

Bar 0 50 20 0 10 40 30

Baz 0 0 0 0 0 0 0

3

Venus 213 0 0 57 0 0 0

Neptune 0 0 0 117 153 0 0

Mars 0 150 0 0 0 0 120

0

Sample Output

CONTEST 1

01 Plutonians 7 1992 261 123 234 345 456 167 278 389

CONTEST 2

01 Bar        5  150  26   0  50  20   0  10  40  30

01 Foo        5  150  26  20  30   0  50  40   0  10

03 Baz        0    0   0   0   0   0   0   0   0   0

03 Xap        0    0   0   0   0   0   0   0   0   0

CONTEST 3

01 Venus      2  270 110 213   0   0  57   0   0   0

02 Mars       2  270 134   0 150   0   0   0   0 120

02 Neptune    2  270 134   0   0   0 117 153   0   0

Source

Mid-Central USA 2002

[Submit]   [Go Back]   [Status]

 #include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h> struct rank {
char name[];
int sol, tot, g, p[], ind;
};
rank ranks[]; int comp(const void *c, const void *d)
{
rank *a = (rank *)c;
rank *b = (rank *)d;
if(a->sol > b->sol) return -;
else if(a->sol < b->sol) return ;
else {
if(a->tot < b->tot) return -;
else if(a->tot > b->tot) return ;
else {
if(a->g < b->g) return -;
else if(a->g > b->g) return ;
else {
return strcmp(a->name, b->name);
}
}
} } int main()
{
// freopen("data.in", "r", stdin);
// freopen("data.out", "w", stdout);
int n = , cnt = ;
while(scanf("%d", &n)) {
if(!n) break;
for(int i = ; i < n; i++) {
double t = ;
ranks[i].sol = , ranks[i].tot = , ranks[i].g = ;
scanf("%s", &ranks[i].name);
for(int j = ; j < ; j++) {
scanf("%d", &ranks[i].p[j]);
if(ranks[i].p[j]) {
ranks[i].sol++;
ranks[i].tot += ranks[i].p[j];
t += log((double)ranks[i].p[j]);
}
}
if(ranks[i].sol > ) {
ranks[i].g = exp(t/ranks[i].sol) + 0.5;
}
}
qsort(ranks, n, sizeof(rank), comp);
printf("CONTEST %d\n", cnt);
cnt++;
for(int i = ; i < n; i++) {
if(i < ) {
printf("");
}
if(i > && ranks[i].sol == ranks[i-].sol && ranks[i].tot == ranks[i-].tot && ranks[i].g == ranks[i-].g) {
ranks[i].ind = ranks[i-].ind;
}
else {
ranks[i].ind = i + ;
}
printf("%d %-10s %d %4d %3d %3d %3d %3d %3d %3d %3d %3d\n", ranks[i].ind, ranks[i].name, ranks[i].sol, ranks[i].tot, ranks[i].g,
ranks[i].p[], ranks[i].p[], ranks[i].p[], ranks[i].p[], ranks[i].p[], ranks[i].p[], ranks[i].p[]); } }
return ;
}

最新文章

  1. 文档分享-Activiti 5.16 用户手册
  2. java异常处理预习
  3. 初级文法课程-第1课:名词的种类/名词的数/名词的所有格/冠词;be 动词、一般动词的现在式
  4. php排序 sort、rsort、asort、arsort、ksort、krsort
  5. 怎么用CorelDRAW插入、删除与重命名页面
  6. 成为IBM精英讲师-一分耕耘 一份收获 同时也多了一份责任!
  7. HDU1025:Constructing Roads In JGShining&#39;s Kingdom(LIS)
  8. 在SQL中导入Excel数据时强制以文本类型导入
  9. JAVA网络编程基础知识
  10. JS冒泡事件与处理
  11. python模块--ip地址转换为整数
  12. idea Library XXXXXXXX has broken classes paths
  13. arcgis for js学习之Graphic类
  14. Spring Security(三十):9.5 Access-Control (Authorization) in Spring Security
  15. Luogu2792 [JSOI2008]小店购物
  16. 《microsoft sql server 2008技术内幕 t-sql语言基础》
  17. [转] webpack3.0踩坑:postcss-loader的使用
  18. Navicat备份、还原mysql数据库
  19. oc 的 协变性与逆变性
  20. 【BZOJ1502】【NOI2005】月下柠檬树 simpson 积分

热门文章

  1. EhCache WebCache 与 SpringMVC集成时 CacheManager冲突的问题
  2. Android studio使用增量更新进行版本升级
  3. 演示对sys用户和普通用户进行审计的示例
  4. C++对析构函数的误解(转)
  5. iOS 导入第三方文件夹时右侧出现问号
  6. Java中数据库连接池原理机制的详细讲解以及项目连接数据库采用JDBC常用的几种连接方式
  7. 一些asp.net使用
  8. 带你玩转JavaWeb开发之一 - HTML快速入门
  9. 【翻译】How To Tango With Django 1.5.4 第四章
  10. 7.2.12. MySQL如何优化ORDER BY