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

求助……我的code为什么过不了啊?还有什么问题没考虑到吗?

Posted by 200730740613 at 2009-04-30 20:49:41 on Problem 3018
#include<stdio.h>

typedef struct
{
	int a[1001];
}Box;

Box b[501];
int r[1001];

void Choose(int n,int m)
{
	int i=1,j,t,count=0,s,c;
	while(i<=n && count<(n-i+1))
	{
		c=0;
		t=0;
		for(;i<=n;i++)
		{
			for(j=1;j<=m;j++)
			{
				if(b[i].a[j]<=r[j])
					break;
			}
			if(j==m+1)
			{
				t=i;
				s=i;
				c++;
				if(count==0)
					count=1;
				break;
			}
		}
		if(t<n&&t>0)
		{
			i=t+1;
		    while(i<=n)
			{
				for(j=1;j<=m;j++)
				{
					if(b[i].a[j]<=b[t].a[j])
						break;
				}
				if(j==m+1)
				{
					c++;
			    	t=i;
				}
			    i++;
			}
		    if(count<c)
				count=c;
			i=s+1;
		}
		else
			break;
	}
	if(count==0)
		printf("Please look for another gift shop!\n");
	else
		printf("%d\n",count);

}

void Sort1(int m)
{
	int i,j;
	for(i=2;i<=m;++i)
	{
		if(r[i]<r[i-1])
		{
			r[0]=r[i];
			for(j=i-1;r[0]<r[j];--j)
				r[j+1]=r[j];
			r[j+1]=r[0];
		}
	}
}

void Sort2(int t,int m)
{
	int i,j;
	for(i=2;i<=m;i++)
	{
		if(b[t].a[i]<b[t].a[i-1])
		{
			b[t].a[0]=b[t].a[i];
			for(j=i-1;b[t].a[0]<b[t].a[j];--j)
				b[t].a[j+1]=b[t].a[j];
			b[t].a[j+1]=b[t].a[0];
		}
	}
}

void Sort3(int n,int m)
{
	int i,j;
	for(i=2;i<=n;i++)
	{
		if(b[i].a[1]<b[i-1].a[1])
		{
			b[0]=b[i];
			for(j=i-1;b[0].a[1]<b[j].a[1];--j)
				b[j+1]=b[j];
			b[j+1]=b[0];
		}
	}
}

int main()
{
	int i,j,n,m;
	while((scanf("%d%d",&n,&m))!=EOF)
	{
		for(i=1;i<=m;i++)
			scanf("%d",&r[i]);
		Sort1(m);
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=m;j++)
				scanf("%d",&b[i].a[j]);
			Sort2(i,m);
		}
		Sort3(n,m);
		Choose(n,m);
	}
	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