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 420788708 at 2010-09-18 21:28:26 on Problem 2092
如此的水题竟然还错,脑残了。
错在这一组了
2 4
1 1 2 2
2 2 3 3
我用了一个sort一个qsort,使用了结构体
附代码,
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
struct ld
{
	int x,y;
}b[250005];
int cmp(const void *elem1,const void *elem2)
{
	struct ld *c=(struct ld *)elem1;
	struct ld *d=(struct ld *)elem2;
	if(c->x==d->x)
		return d->y-c->y;
	return c->x-d->x;
}
int main()
{
	int a[250005];
	int i,k,j,s,rem,t,g;
	while(scanf("%d%d",&i,&j)&&(i||j))
	{
		memset(b,0,sizeof(b));
		memset(a,0,sizeof(a));
		s=i*j;
		for(k=0;k<s;k++)
		scanf("%d",&a[k]);
		sort(a,a+k);
		rem=1;g=0;
		for(k=1;k<s;k++)
		{
			if(a[k-1]!=a[k])
			{
				b[g].x=rem;
				b[g].y=a[k-1];
				g++;
				rem=1;
			}
			else
				rem++;
		}
		if(a[k-1]!=a[k-2])
		{
			b[g].x=1;
		}
		else
		{
			b[g].x=rem;
		}
		b[g].y=a[k-1];
		g++;
		qsort(b,g,sizeof(b[0]),cmp);
		t=b[g-1].x;
		for(i=g-2;i>=0;i--)
			if(b[i].x!=t)break;
		printf("%d ",b[i].y);
		t=b[i].x;
		for(i--;i>=0;i--)
		{
			if(b[i].x!=t)
				break;
			printf("%d ",b[i].y);
		}
		printf("\n");
	}
	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