相同的雪花

相同的雪花

时间限制:1000 ms  |  内存限制:65535 KB

难度:4

描述
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.

输入
The first line of the input will contain a single interger T(0<T<10),the number of the test cases.

The first line of every test case 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.

输出
For each test case,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.

样例输入
1
2
1 2 3 4 5 6
4 3 2 1 6 5
样例输出
Twin snowflakes found.

代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define Max_size 1000000
#define Key 999983
struct node
{
	int v[6];
}s[Max_size];
int found(int m)
{
	return m%Key;
}
bool equals(node *a,node *b)
{
	int p,q,i,j;
	for(i=0;i<6;i++)
	{
		for(j=0;j<6;j++)
		{
			if(a->v[i]==b->v[j])
			{
				int count=0;
				p=i;
				q=j;
				while(a->v[p]==b->v[q]&&count<5)
				{
					p=(p+1)%6;q=(q+1)%6;
					count++;
				}
				if(count==5)
				{
					return true;
				}
				count=0;
				p=i;
				q=j;
				while(a->v[p]==b->v[q]&&count<5)
				{
					p=(p+1)%6;
					q=(q==-1?5:q-1);
					count++;
				}
				if(count==5)
				{
					return true;
				}
			}
		}
	}
	return false;
}
bool found_hash(node t,int sum)
{
	for(int k=found(sum);;k++)
	{
		if(k==Key)
		{
			k=k%Key;
		}
		if(s[k].v[0]==-1)
		{
			s[k]=t;
			return false;
		}
		if(equals(&s[k],&t))
		{
			return true;
		}
	}
	return false;
}
int main(void)
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		node m;
		bool flag=false;
		int sum,n,i,j;
		memset(s,-1,sizeof(s));
		scanf("%d",&n);
		for(i=0;i<n;i++)
		{
			sum=0;
			for(j=0;j<6;j++)
			{
				scanf("%d",&m.v[j]);
				sum=sum+m.v[j];
			}
			if(!flag)
			{
				flag=found_hash(m,sum);
			}
		}
		if(flag)
			printf("Twin snowflakes found.\n");
		else
		    printf("No two snowflakes are alike.\n");
	}
	return  0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-09-30 00:45:51

相同的雪花的相关文章

07-定时器之雪花

*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } a { color: #4183C4; } a.absent { color: #cc0000; } a.anchor { display: block; padding-left: 30px; margin-left: -30px; cursor: pointer; position: absolute

ffmpeg windows 雪花声解决方法

替换所有文件里的<math.h>为<mathimf.h>即可. 我用ffmpeg-0.6.3版测试时,好像mathimf.h文件和其他文件有冲突,需要修改源码. 和qdm2.c文件中的 QDM2Complex *complex;声明相冲突,修改为QDM2Complex *complex1:即可. 和g726.c文件中的static int16_t g726_decode(G726Context* c, int I)中的I冲突,修改为I1即可. 修改完变量声明,同时需修改相关代码,改

jQuery效果—雪花飘落

实现思路 1.在一定的频率下在页面中生成一定数目的雪花从上往下飘落: 2.在指定的时间内飘落后移除页面: 3.可设置雪花的大小,在一定范围内随机雪花大小: 4.什么时间后清除生成雪花,停止函数. js代码 (function($){ $.fn.snow = function(options){ var $flake = $('<div class="flake" />').css({'position': 'absolute', 'top': '-50px'}), docu

【OpenGL】Shader实例分析(七)- 雪花飘落效果

转发请保持地址:http://blog.csdn.net/stalendp/article/details/40624603 研究了一个雪花飘落效果.感觉挺不错的.分享给大家,效果例如以下: 代码例如以下: Shader "shadertoy/Flakes" { // https://www.shadertoy.com/view/4d2Xzc Properties{ iMouse ("Mouse Pos", Vector) = (100,100,0,0) iChan

视频质量诊断----雪花噪声检测

雪花噪声即椒盐噪声,以前黑白电视常见的噪声现象. 原理 准备0°,45°,90°,135°4个方向的卷积模板. 用图像先和四个模板做卷积,用四个卷积绝对值最小值Min来检测噪声点. 求灰度图gray与其中值滤波图median. 判断噪声点:fabs(median-gray)>10 && min>0.1. 噪声点占整幅图像的比较即为雪花噪声率. 三.结果演示 雪花噪声率:0.67 0.63 0.15 1.0 雪花噪声率:0.65 1.0 Demo演示下载地址:http://fil

原生js实现雪花飘落效果

雪花飘落的效果实现步骤:1.使用setInterval定时器每800毫秒创建一个雪花:2.把每一个雪花作为参数传进动态下落的方法中即可. <style> *{padding: 0;margin: 0;} body{ background:#000; width: 100%; height: 100%; overflow:hidden; } </style> <div id="flame"></div> js实现代码: <script

canvas雪花效果核心代码

var ca = document.getElementById("ca"); var ctx = ca.getContext('2d'); //生成n~m之间的随机数的函数 function random(n,m){ return Math.floor(Math.random() * (m - n) + n); } //角度转弧度的函数 function toRd(angle){ return angle * Math.PI / 180; } //设置变量存储画布的最大宽高度 var

canvas制作雪花效果

<!DOCTYPE html><html> <head>    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />    <title>圣诞主题</title>    <link rel='stylesheet' href='common.css' />    <link rel="

iOS 雪花动画与跑马灯

这篇是接着上一篇, 关于动画效果的收集篇, 这篇介绍了跑马灯动画以及下落雪花动画, 请看, 话说最近怎么不在状态呢, 好伤感(囧~). 上一篇 - iOS 仿YY直播心形动画 & 烟花动画 跑马灯效果演示 这里贴出使用代码, 详细请下载Demo查看 下载即用~ 快餐 - -Star鼓励 下载后, 在VC中这样使用, 当然Demo中也有体现 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loa

PHP雪花背景验证码

ValidateCode.class.php 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79