# A - SnowflakeSnowSnowflakes解题报告（黄杰）

3379人阅读 评论(0)

A - SnowflakeSnowSnowflakes
Time Limit:4000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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<stdio.h>
#include<memory.h>
const int M=50021;//定义一个大素数，从而通过取模减小内存。
int hash[50022][7],sel[50022],a[100001][7];
int main()
{
int n,i,j,sum,k,ok1,ok2,ok3;
scanf("%d",&n);
for(i=0;i<n;i++)
for(j=0;j<6;j++)
scanf("%d",&a[i][j]);
memset(sel,0,sizeof(sel));
memset(hash,0,sizeof(hash));
ok3=0;
for(i=0;i<n;i++)
{
sum=0;
for(j=0;j<6;j++)
sum+=a[i][j];
sum=sum%M;//因为sum可能很大，所以对一个大素数取模，这样减小hash数列的范围。
if(sel[sum]==0)//sel数组用来判断此时hash数组上对应的是否已存在，不存在则记录1，且将此部分赋给hash数组。
{
sel[sum]=1;
for(k=0;k<6;k++)
hash[sum][k]=a[i][k];
}
else//如该位置上已存在，则比较是否相同。
{
for(k=0;k<6;k++)//比较两集合是否互为子集。
{
ok1=0;
for(j=0;j<6;j++)
if(hash[sum][k]==a[i][j])
{
ok1=1;
break;
}
if(ok1==0)
{
break;
}
}
for(k=0;k<6;k++)
{
ok2=0;
for(j=0;j<6;j++)
if(hash[sum][j]==a[i][k])
{
ok2=1;
break;
}
if(ok2==0)
break;
}
if(ok1==1&&ok2==1)//互为子集则有相同的，输出并退出，不用再循环。
{
printf("Twin snowflakes found.\n");
ok3=1;
break;
}
}
}
if(ok3==0)
printf("No two snowflakes are alike.\n");
return 0;
}

0
0

【直播】机器学习&数据挖掘7周实训--韦玮
【套餐】系统集成项目管理工程师顺利通关--徐朋
【直播】3小时掌握Docker最佳实战-徐西宁
【套餐】机器学习系列套餐（算法+实战）--唐宇迪
【直播】计算机视觉原理及实战--屈教授
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之矩阵--黄博士
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之凸优化--马博士
【套餐】Javascript 设计模式实战--曾亮

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：206030次
• 积分：3537
• 等级：
• 排名：第9278名
• 原创：127篇
• 转载：49篇
• 译文：0篇
• 评论：14条
阅读排行
评论排行
最新评论