NIT,Problem2 Elephant

http://acm.nit.net.cn/showproblem.jsp?pid=1002

不知道为什么总是WA,测试没遇到问题。把代码贴在这里

#include <stdio.h>

#define TOTAL 1000

int w[TOTAL];
int s[TOTAL];
int a[TOTAL];
int b[TOTAL];
int c[TOTAL];
int layer[TOTAL];

void swap(int *, int *);
void sort(int []);
int findList();
void pf(int);


int main()
{
	int i, n;
	scanf("%d",&n);

	for(i=0; i< n; i++)
	{
		scanf("%d%d",&w[i], &s[i]);
	}

	sort(w);

	n=findList();

	printf("%d\n", n);

	for(i = (int)TOTAL -1; i >= 0; i--)
	{
		if(layer[i] == n)
		{
			pf(i);
			break;
		}
	}

	return 0;
}

void sort(int t[])
{
	int i,j;
	a[0]=1;
	for(i=1; i < TOTAL && t[i] != 0; i++)
	{
		a[i]=i+1;
		for(j=i; j >= 0; j--)
		{
			if(t[j] < t[j-1])
			{
				swap(&t[j], &t[j-1]);
				swap(&s[j], &s[j-1]);
				swap(&a[j], &a[j-1]);
			}
		}
	}
}

void swap(int * a, int * b)
{
	int temp = *a;
	*a = *b;
	*b = temp;
}

int findList()
{
	int i, j;
	int k=0;
	int temp = 0;
	b[0] = 1;
	c[0] = 0;
	layer[0] = 1;

	for(i=1; i < TOTAL && s[i] != 0; i++)
	{
		b[i] = 1;
		c[i] = i;
		layer[i] = 1;
		k=i;

		for(j=0; j<i; j++)
		{

			if(s[i] < s[j] && b[j] >= b[i] && w[i] != w[j])
			{
				b[i] = b[j] + 1;
				k = j;
			}
		}


		c[i] = k;
		if(k != i)
		layer[i] = layer[k] + 1;

		if(temp < b[i])
			temp = b[i];

	}
	return temp==0 ? 1: temp;
}


void pf(int i)
{
	if(layer[i] == 1)
	{
		printf("%d\n", a[i]);
		return;
	}
	pf(c[i]);
	printf("%d\n", a[i]);
}







 

 

你可能感兴趣的:(C++,c,jsp,C#,J#)