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

                    Snowflake Snow Snowflakes
    Time Limit: 4000MS   Memory Limit: 65536K
    Total Submissions: 48646   Accepted: 12703

    Description

    You may have heard that no two snowflakes are alike. Your task is to write a program to determine whether this is really true. Your program will read information about a collection of snowflakes, and search for a pair that may be identical. Each snowflake has six arms. For each snowflake, your program will be provided with a measurement of the length of each of the six arms. Any pair of snowflakes which have the same lengths of corresponding arms should be flagged by your program as possibly identical.

    Input

    The first line of input will contain a single integer n, 0 < n ≤ 100000, the number of snowflakes to follow. This will be followed by n lines, each describing a snowflake. Each snowflake will be described by a line containing six integers (each integer is at least 0 and less than 10000000), the lengths of the arms of the snow ake. The lengths of the arms will be given in order around the snowflake (either clockwise or counterclockwise), but they may begin with any of the six arms. For example, the same snowflake could be described as 1 2 3 4 5 6 or 4 3 2 1 6 5.

    Output

    If all of the snowflakes are distinct, your program should print the message:
    No two snowflakes are alike.
    If there is a pair of possibly identical snow akes, your program should print the message:
    Twin snowflakes found.

    Sample Input

    2
    1 2 3 4 5 6
    4 3 2 1 6 5

    Sample Output

    Twin snowflakes found.

    思路:
    虽然过了---但是代码是错的。
    这是由于,我考虑的雪花相同,就是6个臂在不考虑相对位置的条件下,完全相同。这样可行,都是discuss告诉我的。。
    不过,如果改成题意相同的样子,也只需要更改一下Hash的方式就行了。
    代码:
    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    typedef unsigned long long ll;
    const int maxn = 100009;
    ll num[8],seed=9371;
    ll state[maxn];
    int Head[maxn],Next[maxn];
    int main()
    {
        int n;
        scanf("%lld",&n);
        ll sum,ss;
        int siz=0;
        memset(Head,-1,sizeof(Head));
        for(int i=1;i<=n;i++){
            sum=0,ss=seed;
            for(int j=1;j<=6;j++){
                scanf("%lld",&num[j]);
            }
            sort(num+1,num+7);
            for(int j=1;j<=6;j++){
                sum+=ss*num[j];
                ss*=ss;
            }
            int h=sum%maxn;
            for(int i=Head[h];i!=-1;i=Next[i]){
                if(state[i]==sum){printf("Twin snowflakes found.");return 0;}
            }
            state[++siz]=sum;
            Next[siz]=Head[h];
            Head[h]=siz;
        }
        printf("No two snowflakes are alike.");
    }
    

      

     
  • 相关阅读:
    关于界面和UI
    Windows Form编程中的Command模式
    转载:从地理学透视中国现代化
    [3sNews, 关外飞雪]2005年3S业界盘点暨《3S新闻周刊》创刊题记
    Bridge? 一个GIS二次开发中常用的设计模式
    2005年GIS技术盘点
    [3sNews]建立GIS人自己的工会,抵制低薪无薪上岗
    2005国产空间信息系统软件测评结果揭晓
    从语义(semantic)GIS和知识表达谈起
    使用编译器来使用宏变量
  • 原文地址:https://www.cnblogs.com/ZGQblogs/p/9461105.html
Copyright © 2011-2022 走看看