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

求解释,求数据,求指导。。。

Posted by 20101289 at 2012-03-26 19:43:16 on Problem 2010
#include<iostream>
#include <algorithm>
using namespace std;
int score[100000],aid1[100000],aid2[100000],aid3[100000]={0},aid4[100000]={0};
int main(void)
{
		int j,i,n1, n,c,f,f1,j1,k,h1;
		int sum=0;
		cin >> n>>c >>f;
		f1=f;n1=n;
		
	for( i = 0;i<c;i++)
	{
		cin >>score[i]>>aid1[i];
		aid2[i]= aid1[i];
	}
	sort(aid1,aid1+c);

		for(k = 0;k<n;k++)
		sum = sum+aid1[k];
		if(sum>f)
			cout<<-1;
		else
		{
	f = f/n;

	for(i = 0;i<c;i++)
		if(f<aid1[i])
			break;

	i = i-1;
	

	n = n/2;

	sum = aid1[i];
	aid3[i]=sum;



	for( j1 = 1;j1<=n;j1++)
	{
		if(i-j1>=0){
			sum = sum+aid1[i-j1];
		    aid3[i-j1]=aid1[i-1];


		}
		if(c-j1>i){
			sum = sum+aid1[c-j1];
		aid3[c-j1]=aid1[c-j1];

		}
		
	}

	while(1)
	{
	
		if(sum > f1){
			sum = sum - aid1[i-j1+1]+aid1[i-j1];
			aid3[i-j1+1]=aid1[i-j1];
			j1--;

			
		}
		else if(j1==-1&&sum>f){
			sum =0;
			for(k = 0;k<c;k++){
			
				aid3[k]=0;

			}

			for(k = 0;k<n1;k++){
				aid3[k]=aid1[i-k];
		      sum = sum+aid3[k];

			  
			}

			
			break;
		}
		else
			break;
	}

	int m = 0;

	for( k = 0;k<c;k++)
		for(int h= 0;h<c;h++)
		{
				if( aid3[k]!= 0 && aid3[k]==aid2[h]){
					aid4[m]=score[h];
					aid2[h]=0;
					

					m++;
					break;
				}

		}
		


		sort(aid4,aid4+n1);

		
			cout<<aid4[n1/2]<<endl;
		}
	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