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 lhy1134157026 at 2018-10-09 01:15:15 on Problem 3349
In Reply To:附上WA的代码和一组测试数据,求大佬指导 Posted by:zz0812 at 2018-08-21 20:25:15
代码来自https://blog.csdn.net/alongela/article/details/8245005
膜拜膜拜
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
 
const int N = 1200010;
const int H = 1200007;
 
struct Node
{
	int num[6];
	int next;
};
Node node[N];
int cur;
int hashTable[H];
 
void initHash()
{
	cur = 0;
	for (int i = 0; i < H; ++i) hashTable[i] = -1;
}
 
unsigned int getHash(int* num)
{
	unsigned int hash = 0;
	for (int i = 0; i < 6; ++i)
	{
		hash += num[i];
	}
	return hash % H;
}
 
bool cmp(int* num1, int* num2)
{
	for (int i = 0; i < 6; ++i)
	{
		if (num1[i] != num2[i]) return false;
	}
	return true;
}
 
void insertHash(int* num, unsigned int h)
{
	for (int i = 0; i < 6; ++i) node[cur].num[i] = num[i];
	node[cur].next = hashTable[h];
	hashTable[h] = cur;
	++cur;
}
 
bool searchHash(int* num)
{
	unsigned h = getHash(num);
	int next = hashTable[h];
	while (next != -1)
	{
		if (cmp(num, node[next].num)) return true;
		next = node[next].next;
	}
	insertHash(num, h);
	return false;
}
 
int main()
{
	int num[2][12];
	int n;
	bool twin = false;
	initHash();
	scanf("%d", &n);
	while (n--)
	{
		for (int i = 0; i < 6; ++i) 
		{
			scanf("%d", &num[0][i]);
			num[0][i + 6] = num[0][i];
		}
		if (twin) continue;
		for (int i = 0; i < 6; ++i)
		{
			num[1][i + 6] = num[1][i] = num[0][5 - i];
		}
		for (int i = 0; i < 6; ++i) 
		{
			if (searchHash(num[0] + i) || searchHash(num[1] + i))
			{
				twin = true;
				break;
			}
		}
	}
	if (twin) printf("Twin snowflakes found.\n");
	else printf("No two snowflakes are alike.\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