http://poj.org/problem?id=3349

Snowflake Snow Snowflakes
Time Limit: 4000MS   Memory Limit: 65536K
Total Submissions: 37609   Accepted: 9878

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.
 #include<cstdio>
#include<algorithm>
#include <cstring>
#include <iostream>
using namespace std;
#define MOD 14997
struct node
{
int len[];
}snow,f[][];
int Hash[]; /*
第一道Hash
判断两个雪花是否相同:
分别是顺时针旋转和逆时针旋转,只要有一次是满足条件的就可以当成是一样的
一开始MOD取了999983,结果MLE了,后来看了一下别人的才取了14997
*/
bool check(node a,node b)
{
int i,j,k;
bool flag;
//顺时针旋转判断
for(i=;i<;i++){
flag=true;
for(j=i,k=;k<;k++,j=(j+)%){
if(a.len[j]!=b.len[k]){
flag=false;break;
}
}
if(flag) return ;
}
//逆时针旋转判断
for(i=;i<;i++){
flag=true;
for(j=i,k=;k<;k++,j=(j+)%){
if(a.len[j]!=b.len[k]){
flag=false;break;
}
}
if(flag) return ;
}
return ;
} int main()
{
int n;
int now;
scanf("%d",&n);
//只有一组样例就不初始化了
bool flag=false;
for(int i=;i<n;i++){
now=;
for(int j=;j<;j++){
scanf("%d",&snow.len[j]);
now+=snow.len[j]%MOD;
}
if(flag) continue;
now%=MOD;
if(Hash[now]>){
for(int j=;j<=Hash[now];j++){
if(check(snow,f[now][j])){
flag=true;break;
}
}
}
Hash[now]++;
f[now][Hash[now]]=snow;
}
if(flag) printf("Twin snowflakes found.\n");
else printf("No two snowflakes are alike.\n");
return ;
}

2016-06-04

												

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

  1. POJ 3349 Snowflake Snow Snowflakes (Hash)

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

  2. 哈希—— POJ 3349 Snowflake Snow Snowflakes

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

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

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

  4. POJ 3349 Snowflake Snow Snowflakes

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

  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(哈希查找,求和取余法+拉链法)

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

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

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

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

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

  9. POJ 3349 Snowflake Snow Snowflakes Hash

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

  10. POJ 3349 Snowflake Snow Snowflakes(哈希)

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

随机推荐

  1. JSP常用标签——JSTL标签和EL表达式

    一.JSTL简介 1.什么是JSTL JSTL是Java中的一个定制标记库集.(这个标记库集不需要自己编写,可以直接使用) 2.为什么要使用JSTL 实现了JSP页面中的代码复用(基于标签库原理,重复 ...

  2. 【转】Tomcat组件生命周期管理

    Tomcat组件生命周期管理 Tomcat中Server,Service,Connector,Engine,Host,Context,它们都实现了org.apache.catalina.Lifecyc ...

  3. 结合DDE指标来分析成本分布的重要作用

    筹码分布集中度90和70是什么意思? (2015-08-14 12:12:27) 转载▼ 标签: 股票 分类: 成交量能.筹码分析   那个集中度90,和集中度70,90和70是什么意思??集中度最大 ...

  4. http://codeforces.com/contest/555/problem/B

    比赛时虽然贪了心,不过后面没想到怎么处理和set的排序方法忘了- -,其实是和优先队列的仿函数一样的... 比赛后用set pair过了... #include <bits/stdc++.h&g ...

  5. 前端新手分析 AJAX执行顺序,数据走向

    我是一名前端的newer 在刚学习AJAX和eJS的时候,对于顺序上面有很大迷惑,现在稍微清楚了一点, 理解不对的地方,还请各位大牛帮助给我指导一下. 总的 服务器和客户端的顺序   一. 除了必要的 ...

  6. UVa 10007 - Count the Trees(卡特兰数+阶乘+大数)

    题目链接:UVa 10007 题意:统计n个节点的二叉树的个数 1个节点形成的二叉树的形状个数为:1 2个节点形成的二叉树的形状个数为:2 3个节点形成的二叉树的形状个数为:5 4个节点形成的二叉树的 ...

  7. [原创]java WEB学习笔记70:Struts2 学习之路-- struts2拦截器源码分析,运行流程

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  8. Thread create 创建进程

    #include "windows.h" #include "iostream" #include "stdio.h" void Start ...

  9. php 警告

    php.ini error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT error_log = /var/log/php-fpm/php ...

  10. java 选择排序法

    public class Test3 { /**@author shaobn * @param 选择排序:将a.length - i个元素分别和第i个元素相比较,小的话就将值调换.依次递减进行排列 * ...