POJ - 1245 Programmer, Rank Thyself
POJ - 1245 Programmer, Rank Thyself
Time Limit: 1000MS |
Memory Limit: 10000KB |
64bit IO Format: %I64d & %I64u |
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
#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 ;
}
POJ - 1245 Programmer, Rank Thyself的更多相关文章
- POJ 2379 ACM Rank Table(排序)
题很水,数据注意一下四点即可: 1.有些team会在一道题AC了之后还提交,这个时候只需要算第一次ac的时间以及这之前的wa,之后的全部忽略.2.如果一道题没有ac,那么在计算时间时不应该加上它的wa ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- poj 2153 Rank List
原题链接:http://poj.org/problem?id=2153 简单题,map,平衡树均可.. map: #include<algorithm> #include<iostr ...
- POJ 2153 Rank List (map映射)
水题,竟然花了那么多时间...主要是不知道为什么,明明在本机上编译过去了,但是用c++提交却编译错误...最后用g++提交AC 题意:给出n个学生的名字,然后给出m个测验. 每个测验给出n个学生的分数 ...
- POJ 2970 The lazy programmer(优先队列+贪心)
Language: Default The lazy programmer Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 1 ...
- poj 2153 Rank List(查找,Map)
题目链接:http://poj.org/problem?id=2153 思路分析: 判断Li Ming的成绩排名,需要在所有的数据章查找成绩比其高的人的数目,为查找问题. 查找问题可以使用Hash表, ...
- POJ 2970 The lazy programmer
The lazy programmer Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 2785 Accepted: 70 ...
- POJ 2970 The lazy programmer(贪心+单调优先队列)
A new web-design studio, called SMART (Simply Masters of ART), employs two people. The first one is ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
随机推荐
- sencha做个简单的登录界面
很多人都在群里问要一个好看的登录界面,我表示很无奈,哪有好看的,每个人的要求不一样,要好看的只有自己做. 下面是我自己整理的一个通用版的登录界面,稍做修改,很容易能变成你想要的界面, 不说废话,直接上 ...
- 李洪强经典面试题136-KVO-KVC
李洪强经典面试题136-KVO-KVC KVC-KVO KVC的底层实现? 当一个对象调用setValue方法时,方法内部会做以下操作: ①检查是否存在相应key的set方法,如果存在,就调用se ...
- Trie字典树 动态内存
Trie字典树 #include "stdio.h" #include "iostream" #include "malloc.h" #in ...
- Thinkphp框架感悟(二)
这次主要分析一下I方法 /** * 获取输入参数 支持过滤和默认值 * 使用方法: * <code> * I('id',0); 获取id参数 自动判断get或者post * I('post ...
- Webform——中国省市三级联动以及IsPostBack
首先要明白Webform的运行顺序,当开始启动时候,首先执行的是Page_Load事件, 当点击任意按钮后,每次点击都要先执行一遍Page_Load(在这里Page_Load里面的事件是给数据控件加载 ...
- Android Studio 环境部署 (转载)
Android Studio的安装和使用过程经常需要下载以来文件和Gradle版本,而Google网站在天朝的访问可谓步履维艰,没有稳定的FQ工具是非常痛苦的.何况,作为一个优秀的程序员,不能访问国外 ...
- 2145334赵文豪《Java程序设计》第2周学习总结
2145334赵文豪<Java程序设计>第2周学习总结 教材学习内容总结 第二周的学习结束了,又是充实的一周,在这周的java学习过程中,我们主要学习了java的基础语法.其中包括类型变量 ...
- Android课程---Android Studio使用小技巧:提取方法代码片段
这篇文章主要介绍了Android Studio使用小技巧:提取方法代码片段,本文分享了一个快速复制粘贴方法代码片段的小技巧,并用GIF图演示,需要的朋友可以参考下 今天来给大家介绍一个非常有用的Stu ...
- 【转】java开源类库pinyin4j的使用
最近CMS系统为了增加查询的匹配率,需要增加拼音检索字段,在网上找到了pinyin4j的java开源类库,提供中文转汉语拼音(并且支持多音字), 呵呵,看了看他的demo,决定就用它了,因为我在实际使 ...
- Yii源码阅读笔记(二十九)
动态模型DynamicModel类,用于实现模型内数据验证: namespace yii\base; use yii\validators\Validator; /** * DynamicModel ...