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

Communication System 1018

Posted by Stone1986 at 2008-09-29 17:38:10
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<set>
struct M
{int width;
int price;
};
int  cmp(const void *a,const void *b)
{M *p=(M*)a;M *q=(M*)b;
return p->price>q->price;
}
using namespace std;
int main()
{M N[101][101];
set<int > P;
set<int>::iterator it;
int t,n,m, num[101];
cin>>t>>n;
for(int i=0;i<t;i++)
{
	for(int j=0;j<n;j++)
		{
		  cin>>num[j];
		  for(int k=0;k<num[j];k++)
			{int width,price;
			  cin>>width>>price; P.insert (width); N[j][k].width=width; N[j][k].price=price;
			}
		}
    for(int l=0;l<n;l++)
	{
		qsort(N+l,num[l],sizeof(M),cmp);
	}
double maxBP=-1;
while(!P.empty())
{it=P.begin ();int width=*it,sumP,Price=-1;
double lBP=-1;
sumP=0;
for(int j=0;j<n;j++)
	{Price=-1;
	for(int k=0;k<num[j];k++)
		{
		if(N[j][k].width>=width){
			Price=N[j][k].price ;break;
			}
		}
	if(Price==-1) break;
	 sumP+=Price;
	}
if(Price!=-1)
	{lBP=(double)width/sumP;
	if(lBP>maxBP) maxBP=lBP;
	}
P.erase(it);
}
printf("%0.3lf\n",maxBP);
}
return 0;
}
给个测试样例 不知道为什么通不过总是 WA
不知道没有考虑那种情况

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