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 xuezhimeng at 2006-08-07 11:10:14 on Problem 1065
源代码:

#include<stdio.h>
#include<algorithm>
using namespace std;

typedef struct
{	
	int len;
	int w;
}stick;


bool cmp(stick x,stick y)
{
	if(x.len<y.len) return 1;   //排序这里,如果我改成if(x.len<=y.len)就超时,不改就WA
	else return 0;
}

int main()
{
	int t;
	int i,j,k;
	scanf("%d",&t);
	for(i=0;i<t;i++)
	{
		stick *a;
		int n;
	
		scanf("%d",&n);
		a = new stick [n];
		for(j=0;j<n;j++)
		{
			scanf("%d %d",&a[j].len,&a[j].w);
		}
		sort(a,a+n,cmp);
//		QSort(a,0,n-1);


		int *flag;
		flag = new int[n];
		for(j =0;j<n;j++)
			flag[j]=0;
		int sum= 0 ;

		for(j = 0;j<n;j++)
		{
			for(k = j+1;k<n;k++)
			{
				if(flag[k] == 0 && a[k].w >= a[j].w)
				{
					flag[k] = 1; 
					sum++;
				}
			}
		}

		printf("%d\n",n-sum);
	}
	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