zoukankan      html  css  js  c++  java
  • poj3349

    hash问题,这道题可以用简单的取余法。

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    using namespace std;
    
    #define maxn 100000
    
    struct Snow
    {
    	int arm[6];
    	Snow *next;
    };
    
    Snow * snow[maxn];
    
    bool same(Snow &a, Snow &b)
    {
    	for (int i = 0; i < 6; i++)
    	{
    		bool ok = true;
    		for (int j = 0; j < 6; j++)
    			if (a.arm[j] != b.arm[(j + i) % 6])
    			{
    				ok = false;
    				break;
    			}
    		if (ok)
    			return true;
    	}
    	for (int i = 0; i < 6; i++)
    	{
    		bool ok = true;
    		for (int j = 0; j < 6; j++)
    			if (a.arm[j] != b.arm[(i + 6 - j) % 6])
    			{
    				ok = false;
    				break;
    			}
    		if (ok)
    			return true;
    	}
    	return false;
    }
    
    bool ins(Snow &a, int index)
    {
    	if (snow[index] == 0)
    	{
    		a.next = snow[index];
    		snow[index] = &a;
    		return true;
    	}
    	Snow *p = snow[index];
    	while (p != 0)
    	{
    		if (same(*p, a))
    			return false;
    		p = (*p).next;
    	}
    	a.next = snow[index];
    	snow[index] = &a;
    	return true;
    }
    
    int main()
    {
    	//freopen("D:\\t.txt", "r", stdin);
    	memset(snow, 0, sizeof(snow));
    	int n;
    	scanf("%d", &n);
    	while (n--)
    	{
    		Snow *temp = new Snow;
    		int sum = 0;
    		for (int i = 0; i < 6; i++)
    		{
    			scanf("%d", &(*temp).arm[i]);
    			sum += (*temp).arm[i];
    		}
    		if (!ins((*temp), sum % maxn))
    		{
    			printf("Twin snowflakes found.\n");
    			return 0;
    		}
    	}
    	printf("No two snowflakes are alike.\n");
    	return 0;
    }
  • 相关阅读:
    E. 因数串
    三点共圆公式
    B-Suffix Array
    线段树求解连续区间问题
    E. Quantifier Question (拓扑排序求前驱和后继)
    CF1344B Monopole Magnets
    Multiset (权值线段树模版)
    459. 重复的子字符串 next数组
    6.21笔试小结
    canva学习笔记
  • 原文地址:https://www.cnblogs.com/rainydays/p/1949279.html
Copyright © 2011-2022 走看看