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

第100题~~贴代码纪念一下

Posted by qitaishui at 2012-03-14 20:33:44 on Problem 1018
贪心~
#include<cstdio>
#include<cstring>
int main()
{
	int t,n,m,b[105][105],fac[105],p[105][105],flag[32767],max,min,low,high,tp;
	scanf("%d",&t);
	while(t--){
		low=9999999,high=0;
		scanf("%d",&n);
		memset(flag,0,sizeof(flag));
		for(int i=0;i<n;i++){
			max=0,min=9999999;
			scanf("%d",&fac[i]);
			for(int j=0;j<fac[i];j++){
				scanf("%d%d",&b[i][j],&p[i][j]);
				flag[b[i][j]]=1;
				if(max<b[i][j])
					max=b[i][j];
				if(min>b[i][j])
					min=b[i][j];
			}
			if(low>min)
				low=min;
			if(high<max)
				high=max;
		}
		double result=0;
		for(int i=low;i<=high;i++){
			if(flag[i]){
				int sum=0;
				for(int j=0;j<n;j++){
					tp=99999999;
					for(int k=0;k<fac[j];k++){
						if(b[j][k]>=i&&p[j][k]<tp){
							tp=p[j][k];
						}
					}
					sum+=tp;
				}
				double temp=(double)i/sum;
				if(result<temp)
					result=temp;
			}
		}
		printf("%.3f\n",result);
	}
}

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