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 hhu_jpbirdy at 2008-12-13 15:15:30 on Problem 1065
#include <iostream>
using namespace std;

struct data
{
	int w,l;
}stick[5010];

int cmp(void const *a,void const *b)
{
	data *x,*y;
	x=(data *)a;
	y=(data *)b;
	if(x->w==y->w) return (x->l-y->l);
	else return (x->w-y->w);
}

int main()
{
	//freopen("a.in","r",stdin);
	int t;
	int i,j;
	bool b[5010];
	cin>>t;
	while(t--)
	{
		int n;
		memset(stick,0,sizeof(stick));
		cin>>n;
		for(i=0;i<n;i++)
			cin>>stick[i].l>>stick[i].w;
		qsort(stick,n,sizeof(data),cmp);
		int res=0;
		i=0;
		memset(b,false,sizeof(b));
			for(i=0;i<n;i++)
				if(b[i]) continue;
				else 
				{
					res++;
					int l=stick[i].l;
					for(j=i+1;j<n;j++)
						if(stick[j].l>=l){b[j]=true;l=stick[j].l;}
				}
		printf("%d\n",res);
	}
	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