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

      

     
  • 相关阅读:
    css的em是根据什么来写的
    向一个对象数组里面添加新的属性 + 将一个对象数组数据拿出来变成另一个对象
    微信里iphone后退不刷新问题解决方案
    进到页面后input输入框自动获取焦点
    jquery checkbox反复调用attr('checked', true/false)只有第一次生效
    js promise中如何取到[[PromiseValue]]
    js 取得当天0点 / 23:59:59 时间
    jQuery获取包括当前元素的HTML
    C++ 实现 STL 标准库和算法(二)template 编程和迭代器粗解 实验楼笔记
    我现在怎么写博客笔记?
  • 原文地址:https://www.cnblogs.com/ZGQblogs/p/9461105.html
Copyright © 2011-2022 走看看