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

      

     
  • 相关阅读:
    我的家庭保险方案推荐
    如何修改Total Commander配件文件的位置
    豆瓣统计-2015
    RESTful API接口设计规范
    正则表达式中 的$1,$2与实际应用
    查询排序:order by case when理解、在order By子句中使用case语句的理解
    架构设计:BFF和Serverless简介
    移动端1px细线解决方案总结
    SpringMVC中实体类属性is开头的字段返回JSON时自动去掉is开头的问题
    详解JS面向对象的三大特征之多态
  • 原文地址:https://www.cnblogs.com/ZGQblogs/p/9461105.html
Copyright © 2011-2022 走看看