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

各位,看看,wa哪里了??

Posted by zqu_Empire at 2009-10-30 15:33:59 on Problem 3038
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define M 50005

struct Data
{
	int start, end, numbercows;
};
Data sent[M], back[M];
int k, n, c, s, b, result;

int cmp(const void *a , const void *b)
{
	struct Data *c = (Data *)a;
	struct Data *d = (Data *)b;
	if (c->end != d->end)
	{
		return c->end - d->end;
	}
	return d->start - c->start;
}

void init()
{
	int i, a, bb, cc;

	for (i = 0, s = 0, b = 0; i < k; i++)
	{
		scanf("%d%d%d", &a, &bb, &cc);
		if (a <= bb)
		{
			sent[s].start = a;
			sent[s].end = bb;
			sent[s++].numbercows = cc;
		}
		else
		{
			back[b].start = bb;
			back[b].end = a;
			back[b++].numbercows = cc;
		}
	}
}

void solve(Data process[], int p)
{
	int i, j, k;

	qsort(process, p, sizeof(process[0]), cmp);
	for (i = 1; i <= c; i++)
	{
		for (j = 0, k = 0; j < p; j++)
		{
			if (process[j].start >= k && process[j].numbercows > 0)
			{
				k = process[j].end;
				process[j].numbercows--;
				result++;
			}
		}
	}
}

int main()
{
	while (scanf("%d%d%d", &k, &n, &c) > 0)
	{
		memset(sent, 0, sizeof(sent));
		memset(back, 0, sizeof(back));
		init();
		result = 0;
		solve(sent, s);
		solve(back, b);
		printf("%d\n", result);
	}
	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