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

      

     
  • 相关阅读:
    【2020-02-13】内容变了,但计划本身没变
    【2020-02-12】新的工作计划方式
    【2020-02-10】煮饭那点家常
    【2020-02-10】生活需要不断地相互协调
    nacicat premium 快捷键
    python 爬虫之 正则的一些小例子
    Python爬虫之Cookie和Session
    Python爬虫之关于登录那些事
    爬虫常用库之pyquery 库
    day 39 jq 学习入门2
  • 原文地址:https://www.cnblogs.com/ZGQblogs/p/9461105.html
Copyright © 2011-2022 走看看