POJ 3349 Snowflake Snow Snowflakes

时间:2022-10-15 00:08:49
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&colon;Snowflake Snow Snowflakes(哈希查找,求和取余法&plus;拉链法)

    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. &lbrack;ACM&rsqb; POJ 3349 Snowflake Snow Snowflakes(哈希查找,链式解决冲突)

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

  6. &lbrack;poj 3349&rsqb; 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 &lt ...

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

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

随机推荐

  1. jquery 离开页面提示信息

    <script> $(window).bind('beforeunload', function () { return '您输入的内容尚未保存,确定离开此页面吗?'; });</s ...

  2. Java 项目优化实战

    https://blog.coding.net/blog/java-coding-performance 1 Visual VM 2 优化一 2.1 背景 2.2 原实现 2.3 剖析 2.4 方案 ...

  3. jquery&lpar;&rpar;的三种&dollar;&lpar;&rpar;

    jQuery中的$以及选择器总结 $号是jQuery”类”的一个别称,$()构造了一个jQuery对象.所以,”$()”可以看作jQuery的”构造函数”(个人观点). 一.$符号 1.$()可以是$ ...

  4. Arcgis-ModelBuilder和Python学习

    老师的一个项目,需求如下: 1)arcgis版本使用9.2: 2)需要发布一个数据入库服务,第三方调用这个服务,就可以将“水窖”点位数据存入到服务器数据库中的“水窖”图层: 3)入库前需要检查“水窖” ...

  5. 初学Javascript对象

    <script> var p=new Object(); //属性 p.width=; p.height=; p.num=; p.autotime=; //方法 p.autoplay=fu ...

  6. perl &sol;m修饰符使用说明

    高级用法: 多行匹配: grok正则和普通正则一样, 默认是不支持匹配回车换行的. perl的/m选项 The /m modifier allows ^ and $ to match immediat ...

  7. bzoj2120&colon; 数颜色 &amp&semi;&amp&semi;bzoj2453&colon; 维护队列

    题目大意: 你小时候玩过弹珠吗? 小朋友A有一些弹珠,A喜欢把它们排成队列,从左到右编号为1到N.为了整个队列鲜艳美观,小朋友想知道某一段连续弹珠中,不同颜色的弹珠有多少.当然,A有时候会依据个人喜好 ...

  8. PHP设置环境变量

    如果提示php命令不存在.说明未设置.设置方法如下 方法一:直接运行命令 [PHP] 纯文本查看 复制代码 ? 1 export PATH=$PATH:/usr/local/xxxx/php/bin ...

  9. Java设计模式(二)

    3.设计模式分类 通常来说设计模式分为三大类,共23种:   1.工厂模式 工厂模式(Factory Pattern)的意义就跟它的名字一样,在面向对象程序设计中,工厂通常是一个用来创建其他对象的对象 ...

  10. JAVA的初始化顺序:

    JAVA的初始化顺序: 父类的静态成员初始化>父类的静态代码块>子类的静态成员初始化>子类的静态代码块>父类的代码块>父类的构造方法>子类的代码块>子类的构造 ...