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

  

 

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

  1. UVa 3349 Snowflake Snow Snowflakes(Hash)

    http://poj.org/problem?id=3349 题意: 给出n片雪花留个角的长度,要求判断是否有一样的雪花. 思路: Hash表的应用. 首先将每个雪花所有角的总长计算出来,如果两片雪花 ...

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

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

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

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

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

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

  5. POJ 3349 Snowflake Snow Snowflakes(哈希)

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

  6. POJ 3349 Snowflake Snow Snowflakes (哈希表)

    题意:每片雪花有六瓣,给出n片雪花,六瓣花瓣的长度按顺时针或逆时针给出,判断其中有没有相同的雪花(六瓣花瓣的长度相同) 思路:如果直接遍历会超时,我试过.这里要用哈希表,哈希表的关键码key用六瓣花瓣 ...

  7. POJ - 3349 Snowflake Snow Snowflakes (哈希)

    题意:给定n(0 < n ≤ 100000)个雪花,每个雪花有6个花瓣(花瓣具有一定的长度),问是否存在两个相同的雪花.若两个雪花以某个花瓣为起点顺时针或逆时针各花瓣长度依次相同,则认为两花瓣相 ...

  8. POJ 3349 Snowflake Snow Snowflakes(哈希表)

    题意:判断有没有两朵相同的雪花.每朵雪花有六瓣,比较花瓣长度的方法看是否是一样的,如果对应的arms有相同的长度说明是一样的.给出n朵,只要有两朵是一样的就输出有Twin snowflakes fou ...

  9. 哈希—— POJ 3349 Snowflake Snow Snowflakes

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

随机推荐

  1. 表单中input name属性有无[]的区别

    1 input数组 如下一个表单: <input type="text" name="username[]" value="Jason" ...

  2. b2b

    sku(Stock Keeping Unit)(件)最小库存量单位. spu(一款) 一种详细的规格参数有时候跟spu,规格参数加上颜色+尺寸什么的唯一确定了一个手机,对应的就是sku spu:一款产 ...

  3. asp.net—WebApi跨域

    一.什么是跨域? 定义:是指浏览器不能执行其他网站的脚本,它是由浏览器的同源策略造成的,是浏览器对JavaScript实施的安全限制. 同源策略限制了以下行为: 1.Cookie.LocalStora ...

  4. Jenkins+PowerShell持续集成环境搭建(七)构建触发器

    Jenkins 有三种类型的构建触发器,如下图: Build after other projects are built:在其他项目构建后构建: Build periodically:定时构建: P ...

  5. Jenkins+PowerShell持续集成环境搭建(一)前期准备

    0. 系统要求 Windows Server:本文章使用的为Windows Server 2012 JDK:本文章使用为JDK 1.8 Windows PowerShell:本文章使用为PowerSh ...

  6. JavaScript的 sourcemap 的理解

    当我们在使用vue-cli 开发项目完成后, 就要进行部署,执行npm run build 命令,你会发现它生成.js文件的同时,还会生成一个对应的.map 文件. 当时查了一下, .map 文件的主 ...

  7. Qt evenFilter()与installEvenFilter()

    1, eventFilter 函数中实现事件过滤器.请注意:该函数在 QObject 类中声明为一个虚函数,因此只能由 QObject 的子类继承使用. 2, installEventFilter函数 ...

  8. Civil 3D 二次开发 新建CLR项目出现错误C2143

    新建CLR项目出现错误C2143 按照Objectarx Training创建.net混合项目,编译时出现一下错误: 原因不明: 解决方法: 在Stdafx.h文件中添加: #define WIN32 ...

  9. BZOJ4712洪水——动态DP+树链剖分+线段树

    题目描述 小A走到一个山脚下,准备给自己造一个小屋.这时候,小A的朋友(op,又叫管理员)打开了创造模式,然后飞到 山顶放了格水.于是小A面前出现了一个瀑布.作为平民的小A只好老实巴交地爬山堵水.那么 ...

  10. python里如何获取当前日期前后N天或N月的日期

    #!/usr/bin/python#_*_ coding:UTF-8_*_ import timeimport datetimeimport mathimport calendar ''' time. ...