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. c# 6.0新特性(二)

    写在前面 上篇文章介绍了c#6.0的using static,Auto Property Initializers,Index Initializers新的特性,这篇文章将把剩下的几个学习一下. 原文 ...

  2. Android音乐播放器的开发实例

    本文将引导大家做一个音乐播放器,在做这个Android开发实例的过程中,能够帮助大家进一步熟悉和掌握学过的ListView和其他一些组件.为了有更好的学习效果,其中很多功能我们手动实现,例如音乐播放的 ...

  3. “耐撕”团队第一次讨论——“抢答器”需求分析

    团队名称:"耐撕" 团队成员:齐嘉亮.刘伟硕.濮成林.郑蕊 项目名称:"抢答器"(有待改善) 第一次讨论 时间:20160316 地点:软件所 人员:全体 内容 ...

  4. window下为apache配置ssl证书

    转载自 子非鱼 的博客稍作修改 第一步:依赖 配置Apache服务器支持https协议和SSL证书,最基本的要求是Apache包含openssl模块.还好apache/bin目录下有libeay32. ...

  5. beta版本贡献率

    队名:攻城小分队 031302410 郭怡锋 : 占比:50% 031302411 洪大钊: 占比:30% 031302206 陈振贵: 占比:10% 031302416 黄伟祥: 占比:10%

  6. (Struts)ActionForm类及表单数据验证

    LoginForm代码: /* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */ pac ...

  7. nnnaaavvv

    <header id="masthead" class="masthead" role="banner"> <h1 cla ...

  8. .Net MVC中访问PC网页时,自动切换到移动端对应页面

    随着移动端的流行,越来越的网站,除了提供PC网页之外,也提供了移动端的H5页面,手机在访问www.xxx.com的时候,能自动跳转到mobile.xxx.com.网上很多在实现时也能使用JS直接进行跳 ...

  9. JS模式:又一个简单的工厂模式

    <!DOCTYPE html> <html> <head> <title></title> </head> <body&g ...

  10. Gson 的使用

    Gson 的使用简介Gson 是 Google 开发的Java API,用于转换Java对象 和 Json 对象. 使用Maven 依赖<dependency> <groupId&g ...