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

Re:map不是更快么?

Posted by MasterLuo at 2008-07-16 21:59:42 on Problem 3640
In Reply To:直接排序才是王道啊~~~ Posted by:xwbsw at 2008-07-16 21:26:03
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

int n, a[5];
long long int s=0;
int main()
{
	map<long long int, int>::iterator itr;
	while(scanf("%d", &n) && n!=0)
	{
		int max=0, result=0;
		map<long long int, int> _map;
		for(int t=0; t<n; t++)
		{
			for(int i=0; i<5; i++)
				scanf("%d", &a[i]);
			s=0;
			sort(a, a+5);
			for(int i=0; i<5; i++)
				s=s*1000+a[i];
			_map[s]++;
			if(_map[s]>max)
				max=_map[s];
		}
		for(itr=_map.begin(); itr!=_map.end(); itr++)
			if(itr->second==max)
				result+=max;
		printf("%d\n", result);
	}
	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