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

BT啊,这样错了~~

Posted by level at 2007-04-29 16:33:33 on Problem 1018
#include<stdio.h>
#include<stdlib.h>
const int max=101;
struct BP
{
	int b,p;
}my[max][max];
int m;
int low[max];
int cb[max*max],ci;
int cmp(const void *x,const void *y)
{
	return ((BP *)x)->p-((BP *)y)->p;
}
int comp(const void *x,const void *y)
{
	return *(int *)x-*(int *)y;
}
void init()
{
	int i,j;
	scanf("%d",&m);
	for(ci=i=0;i<m;i++)
	{
		scanf("%d",&low[i]);
		for(j=0;j<low[i];j++)
		{
			scanf("%d %d",&my[i][j].b,&my[i][j].p);
			cb[ci++]=my[i][j].b;
		}
		qsort(my[i],low[i],sizeof(BP),cmp);
	}
	qsort(cb,ci,sizeof(cb[0]),comp);
}
int find(int row,int number)
{
	int i;
	for(i=0;i<low[row];i++)
		if(my[row][i].b>=number)
			return my[row][i].p;
	return -1;
}
void work()
{
	int i,j,s;
	double maxn=0,sum;
	cb[ci]=0;//这个不要就WA,倒!.
	for(i=0;i<ci;i++)
		if(cb[i]!=cb[i+1])
		{
			for(sum=j=0;j<m;j++)
			{
				s=find(j,cb[i]);
				if(s<0) break;
				sum+=s;
			}
			if(j<m) continue;
			if(cb[i]/sum>maxn) maxn=cb[i]/sum;
		}
	printf("%.3lf\n",maxn);
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		init();
		work();
	}
	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