Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴一个AC代码吧~

Posted by cfanfrank at 2010-04-17 19:32:30 on Problem 1245
求geometric的时候,转换成pow(t1*t2*...*tn, 1/n)比较好一点
用printf完全可以解决输出问题。。


#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:\\test\\in.txt", "r", 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;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator