poj 1245 Programmer, Rank Thyself

Programmer, Rank Thyself

Time Limit: 1000MS
Memory Limit: 10000K

Total Submissions: 901
Accepted: 366

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

 

好久没做题了实在是不行啊 其实是个水题,但是折腾好半天 wa了无数次。。还是没搞出来 不得已看了人家的代码,结果自己还是wa。。。

无语了。。先贴别人的代码 有空接着搞。。。

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
 
 
struct node {
	char name[16];
	int tm[7], sum, sol, geo;
};
 
 
struct node in[24];
int N;
 
 
int cmp(const void *_a, const void *_b)
{
	struct node *a, *b;
 
 
	a = (struct node *)_a;
	b = (struct node *)_b;
 
 
	if (a->sol != b->sol)
		return b->sol - a->sol;
	if (b->sum != a->sum)
		return a->sum - b->sum;
	if (b->geo != a->geo)
		return a->geo - b->geo;
	return strcmp(a->name, b->name);
}
 
 
int main()
{
	int c, i, j, r;
	double e;
	struct node *t;
 
 
	freopen("E:\\c++\\oj\\t.txt","rt",stdin);
 
 
	for (c=1 ; scanf("%d",&N),N ; c++) 
	{
		for (i=0 ; i<N; i++) 
		{
			t = &in[i];
			scanf("%s", t->name);
			t->sum = t->sol = t->geo = 0;
			e = 1;
			
			for (j=0 ; j<7 ; j++) 
			{
				scanf("%d", &t->tm[j]);
				if (!t->tm[j])
					continue;
				t->sum += t->tm[j];
				t->sol++;
				e *= t->tm[j];
			}
			if (t->sol)
				t->geo = (int)(pow(e, (double)1/t->sol) + 0.5);
		}
		
		qsort(in, N, sizeof(in[0]), cmp);
		
		printf("CONTEST %d\n", c);
		for (r = i = 0; i < N; i++) 
		{
			if (i && (in[i].sol != in[i - 1].sol || 
					  in[i].sum != in[i - 1].sum ||
					  in[i].geo != in[i - 1].geo))
			{
				r = i;
			}	
			printf("%.2d %-10s%2d%5d%4d", 
					r + 1, in[i].name, 
					in[i].sol, in[i].sum, in[i].geo
					);
			for (j=0 ; j<7 ; j++)
				printf("%4d", in[i].tm[j]);
			printf("\n");
		}
	}
	return 0;
}

转载于:https://www.cnblogs.com/w0w0/archive/2011/11/24/2261510.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值