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

什么不说贴代码!

Posted by chenxuan123456789 at 2012-08-01 15:06:31 on Problem 1065
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define M 5000+10
typedef struct stick
{
	int l;
	int w;
}sticks;
sticks s[M];
int flag[M];
int cmp(const void *_a,const void *_b)
{
	sticks *a=(sticks*)_a;
	sticks *b=(sticks*)_b;
	if(a->l==b->l)
	return a->w-b->w;
	return a->l-b->l;
}
int main()
{
	int cases,i,j,ans,n,k;
	scanf("%d",&cases);
	while(cases--)
	{
		scanf("%d",&n);
		for(i=0;i<n;i++)
		scanf("%d %d",&s[i].l,&s[i].w);
		qsort(s,n,sizeof(sticks),cmp);
	 	ans=0;
		memset(flag,0,sizeof(flag));
		for(i=0;i<n;i++)
		{
			if(flag[i])
			continue;
			k=i;
			for(j=i+1;j<n;j++)
			 if(s[k].w<=s[j].w&&!flag[j])
			 {
				 k=j;
				 flag[j]=1;
			 }
			 ans++;
		}
		printf("%d\n",ans);
	}
	return 1;
}

		 

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