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. 我的权限系统设计实现MVC4 + WebAPI + EasyUI + Knockout(四)授权代码维护

    一.前言 权限系统设计中,授权代码是用来控制数据访问权限的.授权代码说白了只是一树型结构的数据,没有什么其它的业务意义.那么这个页面的功能也就非常简单授权代码维护:新增.修改.删除授权代码数据. 二. ...

  2. 关于一个每天请求50W次接口的设计实现过程

    从大学开始关注博客园,到工作之后注册了博客园账号,直至今日终于能够静下心来将自己个人的所学,所得,所悟能够分享出来与大家分享,好开心~ 言归正传,需求背景是博主所在的公司为一个在线OTA公司,客户端上 ...

  3. IE8/9的console之坑

    这几天遇到个深坑,在改别人代码时,发现ajax在ie8下请求不成功.清理了缓存后,可以请求成功!(清理缓存只是表象而已,后文说原因) 后来慢慢看代码,发现ajax成功回调了!在success回调里,我 ...

  4. OSX 上安装 Scrapy 的那些坑

    Scrapy 这个爬网框架真心不错,但在OSX上安装总是会出现各种的问题,在这里就作一个收集汇总.我的系统环境是 OS X El Capitan (10.11.1) 首先要保证 pip , virtu ...

  5. 图片百分百问题 z-index问题

    遇到的问题:     1.图片设置宽高都为100%,为什么高度没有100%呢?  我日了狗了!         答:因为图片默认高度大于包含框, 此时元素的高度100%将不会参照父元素? 继承出现了问 ...

  6. 如何在Dreamweaver中使用emmet

    by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=3666 一.emmet ...

  7. javascript键盘输入控制

    获取键盘控制事件 document.onkeydown = keyDown 当浏览器读到这个语句时,无论按下键盘上的哪个键,都将呼叫KeyDown()函数. 不同浏览器的实现: Netscape Ne ...

  8. ASP.NET Web API实现POST报文的构造与推送

    毕设和OAuth协议相关,而要理解OAuth协议就必须理解HTTP GET/POST方法.因此研究了一下如何使用Web API或MVC构造POST报文并实现客户端与服务器端的交互. 我使用的工具是Vi ...

  9. css左右侧自动填充宽度布局

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  10. Netbeans 中的编译器相关配置

    gcc-core:C 编译器 gcc-g++:C++ 编译器 gdb:GNU 调试器 make:"make" 实用程序的 GNU 版本