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.");
    }
    

      

     
  • 相关阅读:
    TypeScript 源码详细解读(3)词法2-标记解析
    TypeScript 源码详细解读(2)词法1-字符处理
    TypeScript 源码详细解读(1)总览
    7年编程语言设计精华总结——写给想创造或正在创造一门新编程语言的同学
    我为什么开发新语言
    CLR值类型和引用类型
    运行时内存模型
    IronPython之基本类型
    .NET 应用程序域?
    .NET程序如何启动?
  • 原文地址:https://www.cnblogs.com/ZGQblogs/p/9461105.html
Copyright © 2011-2022 走看看