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

题解:

哈希,个人理解哈希就是一种暴力手法,选出符合要求的情况

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN=1e5+10;
const int MAXM=1e6;
const int pri=999983;
struct node{
int a[6];
}x[MAXN];
vector<int >G[MAXM];
inline bool scan_d(int &num)
{
char in;bool IsN=false;
in=getchar();
if(in==EOF) return false;
while(in!='-'&&(in<'0'||in>'9')) in=getchar();
if(in=='-'){ IsN=true;num=0;}
else num=in-'0';
while(in=getchar(),in>='0'&&in<='9'){
num*=10,num+=in-'0';
}
if(IsN) num=-num;
return true;
}
int main()
{
int n;
scanf("%d",&n);
int flag=0,MAX=0;
for (int i = 0; i <n ; ++i) {
for (int j = 0; j <6 ; ++j) {
scan_d(x[i].a[j]);
}
int z=0;
z=((x[i].a[0]+x[i].a[2]+x[i].a[4])&(x[i].a[1]+x[i].a[3]+x[i].a[5]))%pri;//此处还可以是,(a[0]+...+a[5])%pir
G[z].push_back(i);
}
int cnt=0;
for (int i = 0; i <=pri ; ++i) {
if(G[i].size()>=2)
{
for (int k = 0; k <G[i].size()-1 ; ++k) {
for (int l = k+1; l <G[i].size() ; ++l) {
for (int s=0;s<6;s++)//顺时针
{
cnt=0;
for (int j = 0,z=0; z<6,j <6 ; ++j,z++)
{
if(x[G[i][k]].a[j]!=x[G[i][l]].a[(z+s)%6])
{
cnt=1;
break;
}
}
if(cnt==0)
{
flag=1;
goto out;
}
}
for (int s=0;s<6;s++)//逆时针
{
cnt=0;
for (int j = 0,z=5; z>=0,j <6 ; ++j,z--)
{
if(x[G[i][k]].a[j]!=x[G[i][l]].a[(z-s+6)%6])
{
cnt=1;
break;
}
}
if(cnt==0)
{
flag=1;
goto out;
}
}
}
}
}
}
out:
if(flag)
{
printf("Twin snowflakes found.\n");
} else
printf("No two snowflakes are alike.\n");
return 0;
}

  

  

Snowflake Snow Snowflakes【Poj3349】的更多相关文章

  1. poj3349 Snowflake Snow Snowflakes【HASH】

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

  2. POJ3349 Snowflake Snow Snowflakes 【哈希表】

    题目 很简单,给一堆6元组,可以从任意位置开始往任意方向读,问有没有两个相同的6元组 题解 hash表入门题 先把一个六元组的积 + 和取模作为hash值,然后查表即可 期望\(O(n)\) #inc ...

  3. POJ3349 Language: Snowflake Snow Snowflakes

    POJ3349 Language: Snowflake Snow Snowflakes 题目:传送门 题解: 链表+hash的一道水题 填个坑补个漏... 代码: #include<cstdio ...

  4. [poj3349]Snowflake Snow Snowflakes(hash)

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

  5. POJ--3349 Snowflake Snow Snowflakes(数字hash)

    链接:Snowflake Snow Snowflakes 判断所有的雪花里面有没有相同的 每次把雪花每个角的值进行相加和相乘 之后hash #include<iostream> #incl ...

  6. POJ3349 Snowflake Snow Snowflakes (hash

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

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

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

  8. Snowflake Snow Snowflakes(哈希表的应用)

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

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

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

随机推荐

  1. eclipse svn 环境搭建

    subversion 1.8.14(r1692801) eclipse 安装插件 1.10.x版本

  2. 【工作中学习1】两个设计模式:Singleton(单例)和 Adapter(适配器)

    好久没有写自己的学习小博客,罪过罪过..最近本菜鸟在项目中接触到经常用到的设计模式,首先是Singleton(单例),这个相信大家都会用到很多,所以自己用代码实现一下,有助于自己学习理解,如有不对,请 ...

  3. 解决javascript四舍五入不准确

    function roundFixed(num, fixed) { var pos = num.toString().indexOf('.'), decimal_places = num.toStri ...

  4. PCB仿真软件与电磁场求解器的算法

    1. 简介 目前商业化的PCB仿真软件主要有: Cadence公司的Sigrity.Ansys公司的SIwave/HFSS.CST公司的CST.Mentor公司的HyperLynx.Polor公司的S ...

  5. Azure 3 月新公布

    Azure 3 月新发布:Power BI Embedded,R Server 和 IoT 套件预测性维护预配置解决方案正式发布,ExpressRoute 部署变更,以及计量名称变更 Power BI ...

  6. 利用C语言编辑画图程序的实现方法

    不知道大家在进行开发县级电网调度自动化系统的时候,是否都会遇到一个问题就是:要绘制一个电力系统一次接线图.大家都应该知道其实电力系统的一次接线图是较为复杂的,如果想要使用一般的编程方法来进行绘制的话, ...

  7. 浏览器中使用calc不识别

    在使用css3中的calc运算函数时,发现浏览器不识别,当时代码是这样的 width:calc(100%-50px); 经过查询官网原来发现这里有个需要注意的地方就是在进行加减运算的时候,必须在运算符 ...

  8. Js parsetInt() 字符串转换,只能转换字符串,数字开头的才会返回数值,否则为NaN,空字符串也返回NaN

    alert(parseInt('456lee')); //456,返回正数部分 alert(parseInt('lee456lee')); //NaN alert(parseInt('lee456le ...

  9. 257. Binary Tree Paths (dfs recurive & stack)

    Given a binary tree, return all root-to-leaf paths. Note: A leaf is a node with no children. Example ...

  10. 【转载】#349 - The Difference Between Virtual and Non-Virtual Methods

    In C#, virtual methods support polymorphism, by using a combination of the virtual and override keyw ...