Snowflake Snow Snowflakes
Time Limit: 4000MS Memory Limit: 65536K
Total Submissions: 27598 Accepted: 7312

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.

Source

CCC 2007

hash函数。。。3750ms。。。险过。。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

struct ST
{
   int a[6];
};

bool cmp(const ST x,const ST y)
{
    bool flag=true;
    for(int i=0;i<6;i++)
    {
        flag=true;
        for(int j=0;j<6;j++)
        {
            if(x.a[j]!=y.a[(j+i)%6])
            {
                flag=false;
                break;
            }
        }
        if(flag) return true;
    }
    for(int i=0;i<6;i++)
    {
        flag=true;
        for(int j=0;j<6;j++)
        {
            if(x.a[5-j]!=y.a[(j+i)%6])
            {
                flag=false;
                break;
            }
        }
        if(flag) return true;
    }
    return false;
}

int main()
{
    int n;
    ST A; bool flag=false;
    vector<ST> hash[17569];
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int sum=0;
        for(int j=0;j<6;j++)
        {
            scanf("%d",&A.a[j]);
            sum+=A.a[j];
        }
        hash[sum%17569].push_back(A);
    }
    for(int i=0;i<17569;i++)
    {
        if(flag) continue;
        int nth=hash.size();
        for(int j=0;j<nth;j++)
        {
            for(int k=j+1;k<nth;k++)
            {
                if(cmp(hash[j],hash[k]))
                {
                    puts("Twin snowflakes found.");
                    flag=true;
                    break;
                }
            }
        }
    }
    if(flag==false)
        puts("No two snowflakes are alike.");
    return 0;
}

* This source code was highlighted by YcdoiT. ( style: Codeblocks )

POJ 3349 Snowflake Snow Snowflakes的更多相关文章

  1. 哈希—— POJ 3349 Snowflake Snow Snowflakes

    相应POJ题目:点击打开链接 Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions ...

  2. POJ 3349 Snowflake Snow Snowflakes(简单哈希)

    Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 39324   Accep ...

  3. poj 3349:Snowflake Snow Snowflakes(哈希查找,求和取余法+拉链法)

    Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 30529   Accep ...

  4. POJ 3349 Snowflake Snow Snowflakes (Hash)

    Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 48646   Accep ...

  5. [ACM] POJ 3349 Snowflake Snow Snowflakes(哈希查找,链式解决冲突)

    Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 30512   Accep ...

  6. [poj 3349] Snowflake Snow Snowflakes 解题报告 (hash表)

    题目链接:http://poj.org/problem?id=3349 Description You may have heard that no two snowflakes are alike. ...

  7. POJ 3349 Snowflake Snow Snowflakes(哈希)

    http://poj.org/problem?id=3349 题意 :分别给你n片雪花的六个角的长度,让你比较一下这n个雪花有没有相同的. 思路:一开始以为把每一个雪花的六个角的长度sort一下,然后 ...

  8. POJ 3349 Snowflake Snow Snowflakes Hash

    题目链接: http://poj.org/problem?id=3349 #include <stdio.h> #include <string.h> #include < ...

  9. hash应用以及vector的使用简介:POJ 3349 Snowflake Snow Snowflakes

    今天学的hash.说实话还没怎么搞懂,明天有时间把知识点总结写了,今天就小小的写个结题报告吧! 题意: 在n (n<100000)个雪花中判断是否存在两片完全相同的雪花,每片雪花有6个角,每个角 ...

随机推荐

  1. Android四大布局及其主要属性

    布局: <LinearLayout></LinearLayout> <RelativeLayout></RelativeLayout> <Fram ...

  2. Orchard特性路线图(其实就是以后将做什么)

    本文链接:http://www.cnblogs.com/souther/p/4539975.html 主目录 近期,我们将注意力集中在完成第一版的发布并且计划开发下一版.特征路线图提及的就是项目涉及到 ...

  3. php中命名空间的使用

    简单使用 命名空间主要解决函数/类冲突的问题.由于PHP中中不允许函数重载,所以我们要使用的到命名空间的.先看一个简单的例子. <?php namespace A; public functio ...

  4. [c#基础]DataTable的Select方法

    引言 可以说DataTable存放数据的一个离线数据库,将数据一下加载到内存,而DataReader是在线查询,而且只进形式的查询,如果后退一步,就不可能了,DataTable操作非常方便,但也有缺点 ...

  5. npm配置代理

    有时候可能因为使用代理,使用npm下载node模块会报"proxy"相关的错误,error提示ECONNECT,好像是这么拼的. 解决办法 1 配置代理 npm config se ...

  6. codevs 1690 开关灯 线段树水题

    没什么好说的,标记put表示开关是否开着. #include<cstdio> #include<cstring> #include<algorithm> using ...

  7. hdu1255 矩阵的交 线段树+扫描线

    /* 不是叶子节点 ,且cnt=1.注意这里,cnt=1确切的意义是什么, 应该是,可以确定,这个区间被完全覆盖了1次, 而有没有被完全覆盖两次或以上则不知道无法确定,那么怎么怎么办了, 只要加上t[ ...

  8. shell中一维数组值得获取

    (1)数组的定义 root@tcx4440-03:~# a=(1 2 3 4) root@tcx4440-03:~# echo ${a[1]}2 root@tcx4440-03:~# a[0]=1ro ...

  9. Rdesktop

    linux远程windows rdesktop是一个开放源码的Window   NT中断服务器的客户端,它实现了远程桌面协议(RDP) rdesktop-1.7.0.tar 下载地址:http://d ...

  10. codevs3243 区间翻转

    题目描述 Description 给出N个数,要求做M次区间翻转(如1 2 3 4变成4 3 2 1),求出最后的序列 输入描述 Input Description 第一行一个数N,下一行N个数表示原 ...