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,给个BT数据也行

Posted by 0huzi0 at 2008-08-05 16:37:36 on Problem 1065
#include<stdio.h>
struct WOOD
{
	int length;
	int weight;
	bool visit;
};
int q(WOOD a[],int low,int high)
{
	WOOD b;
	b=a[low];
	while(low<high)
	{
		while(low<high && (a[high].length<b.length || (a[high].length==b.length && a[high].weight<=b.weight)))
			high--;
		a[low]=a[high];
		while(low<high && (a[high].length>b.length || (a[high].length==b.length && a[high].weight>=b.weight)))
			low++;
		a[high]=a[low];
	}
	a[low]=b;
	return low;
}
void qs(WOOD a[],int low,int high)
{
	if(low<high)
	{
		int m=q(a,low,high);
		qs(a,low,m-1);
		qs(a,m+1,high);
	}
}
int main()
{
//	freopen("1.txt","r",stdin);
	WOOD wood[5000],test;
	int n,sum,i,jsum,spsum;
	scanf("%d",&n);
	while(n--)
	{
		jsum=0;
		spsum=0;
    	scanf("%d",&sum);
    	for(i=0;i<sum;i++)
		{
    		scanf("%d%d",&wood[i].length,&wood[i].weight);
			wood[i].visit=false;
		}
    	qs(wood,0,sum-1);
//		for(i=0;i<sum;i++)
//	    	printf("%d %d\n",wood[i].length,wood[i].weight);
		while(jsum!=sum)
		{
			test.length=300000;
	    	test.weight=300000;
			spsum++;
			for(i=0;i<sum;i++)
				if(!wood[i].visit && wood[i].length<=test.length && wood[i].weight<=test.weight)
				{
					test.length=wood[i].length;
					test.weight=wood[i].weight;
					jsum++;
					wood[i].visit=true;
				}
		}
		printf("%d\n",spsum);
	}
	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