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

RE.. 不太明白。。请过的朋友给点提示

Posted by yescrystal at 2006-12-08 20:38:59 on Problem 2010
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

const int maxn = 20010;
const int maxc = 100010;

int n, nc, all;
struct Cow{int s, a;}ss[maxn], sc[maxn];

int cmp1(const void * a, const void * b)
{
	return (*(Cow *)a).s-(*(Cow *)b).s;
}

int cmp2(const void * a, const void * b)
{
	return (*(Cow *)a).a-(*(Cow *)b).a;
}

void init()
{
	int i;
	//initiation
	//input
	scanf("%d%d%d", &n, &nc, &all);
	for(i=0; i<nc; i++)
		scanf("%d%d", &ss[i].s, &ss[i].a);
	memcpy(sc, ss, nc*sizeof(Cow));
	qsort(ss, nc, sizeof(Cow), cmp1);
	qsort(sc, nc, sizeof(Cow), cmp2);
	//pretreatment
}

void work()
{
	int i, j, cnta, cntb, maxi = -1, sum;
	int k = n/2;
	for(i = k; i<nc-k; i++)  //枚举中位数
	{
		j = cnta = cntb = sum = 0;
		while(cnta<k || cntb<k && j<nc) //在以aid值排序的序列中检验是否全加小于F
		{
			if(sc[j].s<ss[i].s && cnta<k) {cnta++; sum += sc[j].a;}
			else if(sc[j].s>ss[i].s && cntb<k) {cntb++; sum += sc[j].a;}
			j++;
		}
		if(cnta>=k && cntb>=k && sum+ss[i].a<=all) maxi = i;
//		while(ss[i].s == ss[i+1].s && i<nc-k) i++; //跳过重复
	}
	if(maxi == -1) printf("-1\n"); //无解的情况
	else printf("%d\n", ss[maxi].s);
}

int main()
{
	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