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 kochat at 2007-05-14 00:42:56 on Problem 1002
In Reply To:用排序还是哈希? Posted by:flykitej at 2007-05-10 15:36:20
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

const int lut[] =
{
	2, 2, 2,
	3, 3, 3,
	4, 4, 4,
	5, 5, 5,
	6, 6, 6,
	7, 0, 7, 7,
	8, 8, 8,
	9, 9, 9, 0,
};

int main()
{
	int count;
	cin >> count;
	vector<string> vec_num;
	vec_num.reserve(count);
	string str, num_str;
	char ch;
	char* bucket = new char[10000001*3];
	memset(bucket, 0, 10000001 * 3 * sizeof(char));

	while ( count-- && cin >> str )
	{
		int i = 0;
		num_str = "";
		while ( (ch=str[i++])!='\0')
		{
			if ( ch == '-')
				continue;
			else if ( ch > '9')
				num_str.append(1, lut[ch-'A'] +'0');
			else
				num_str.append(1, ch);
		}
		i = atoi(num_str.c_str()) * 3;
		(*((int*)&(bucket[i])))++;
	}

	bool bNoDuplicate = true;
	char* p = bucket;
	char des[20];
	for ( int i = 0; i < 10000000; i++, p+=3 )
	{
		if ((count = (*((int*)p) & 0x00FFFFFF)) > 1)
		{
			bNoDuplicate = false;
			sprintf(des, "%07d %d", i, count);
			str = des;
			str.insert(3, "-");
			cout << str << endl;
		}
	}

	if ( bNoDuplicate )
		cout << "No duplicates." << endl;

	delete[] bucket;
	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