zoukankan      html  css  js  c++  java
  • POJ 3349 Snowflake Snow Snowflakes

    poj 3349 

    雪花是否相同

    #include<iostream>
    #include <algorithm>
    #include <stdio.h>
    #include <cstdio>
    
    using namespace std;
    
    #define size 100010
    
    int arr[size][6];
    int n;
    
    struct node{
        int key;
        node *next;
    };
    
    node HashTable[size];
    node HashPool[size];
    int index = 0;
    
    node *getNewNode()
    {
        return &HashPool[index++];
    }
    
    void insert(int key,node *newNode)
    {
        node *tmp = &HashTable[key];
        newNode->next = tmp->next;
        tmp->next = newNode;
    }
    
    bool isSame(int a,int b)
    {
        sort(arr[a],arr[a]+6);
        sort(arr[b],arr[b]+6);
        for(int i = 0; i < 6;i++)
        {
            if(arr[a][i] != arr[b][i])
                return false;
        }
    
        return true;
    }
    
    int getKey(int a[6])
    {
        int sum = 0;
        for(int i = 0; i < 6; i++)
            sum += a[i];
    
        return sum%99991;
    }
    bool search(int key,int i)
    {
        node *tmp = &HashTable[key];
        tmp = tmp -> next;
        while(tmp != NULL)
        {
            int j = tmp->key;
            tmp = tmp->next;
            if(isSame(i,j))
                return true;
        }
    
        return false;
    
    }
    
    int main()
    {
        scanf("%d",&n);
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < 6; j++)
            {
                scanf("%d",&arr[i][j]);
            }
        }
    
        for(int i = 0; i < n ;i++)
        {
            int key = getKey(arr[i]);
            bool flag = search(key,i);
            if(flag)
            {
                printf("%s
    ", "Twin snowflakes found.");
                return 0;
            }
            else
            {
                node *newNode = getNewNode();
                newNode->key = i;
                insert(key,newNode);
            }
    
        }
        printf("%s
    ", "No two snowflakes are alike.");
        return 0;
    }
  • 相关阅读:
    hdu 6085 bitset优化
    hdu 6070 二分答案+线段树
    hdu 6069 区间筛
    hdu 6058 并查集
    CF 835D D. Palindromic characteristics 字符串hash
    (转)Linux整合apache和tomcat构建Web服务器
    iTunes备份文件路径
    mac下Apache添加限速模块mod_bw
    mac显示隐藏文件夹
    Mac OS X下HomeBrew安装卸载
  • 原文地址:https://www.cnblogs.com/zyqBlog/p/8033850.html
Copyright © 2011-2022 走看看