POJ 3349 Snowflake Snow Snowflakes

版权声明:听说这里让写版权声明~~~ https://blog.csdn.net/m0_37691414/article/details/82153850

题意:有n片雪花,问是否有两片完全相同呢? 雪花都是六棱的,如果六棱的长度对应完全相等,则认为两片雪花相同。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
using namespace std;
const int N = 15000;
const int L = 6;
struct node{
	int a[6];
};
vector<node> snow[N];
int getHash(node SNOW){
	int key = 0;
	for(int i = 0; i < L; ++i)
		key += SNOW.a[i];
	return key %  14997;
}
int cmp(node x, node y){
	int i, j, st;
	for(st = 0; st < 6; ++st){
		for(i = st, j = 0; j < 6; ++j, i = (i + 1) % 6)
			if(x.a[i] != y.a[j])	break;
		if(j == 6)	return 1;
	}
	for(st = 0; st < 6; ++st){
		for(i = st, j = 0; j < 6; ++j, i = (i + 5) % 6)
			if(x.a[i] != y.a[j])	break;
		if(j == 6)	return 1;
	}
	return 0;
}
int main(){
	int n;
	node SNOW;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i){
		for(int j = 0; j < L; ++j)
			scanf("%d", &SNOW.a[j]);
		int pos = getHash(SNOW);
		for(int j = 0; j < snow[pos].size(); ++j)
			if(cmp(SNOW, snow[pos][j])){
				puts("Twin snowflakes found.");
				return 0;
			}
		snow[pos].push_back(SNOW);
	}
	puts("No two snowflakes are alike.");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_37691414/article/details/82153850