相同的雪花

时间限制: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 <iostream>
#include <cstdio> using namespace std; typedef struct snow{
int a[];
snow *next;
};
snow *s[]; int fin(int b[],int sum){
snow *p;
p=s[sum]->next;
while(p){
for(int i=;i<;i++){
int j;
if(b[i]==p->a[]){
for(j=;j<;j++){
if(b[i+j]%!=p->a[j]){
break;
}
}
if(j==){
return ;
}
for(j=;j<;j++){
if(b[((i-j%+)%)]!=p->a[j]){
break;
}
}
if(j==){
return ;
}
}
}
p=p->next;
}
p=new snow;
for(int i=;i<;i++){
p->a[i]=b[i];
}
p->next=s[sum]->next;
s[sum]->next=p;
return ;
} int main()
{
int n;
int t;
int b[];
int sum;
int flag;
scanf("%d",&n);
for(int i=;i<;i++){
s[i]=new snow;
s[i]->next=NULL;
}
while(n--){
scanf("%d",&t);
flag=;
for(int i=;i<t;i++){
sum=;
for(int j=;j<;j++){
scanf("%d",&b[j]);
sum+=b[j];
}
sum%=;
if(!flag){
if(fin(b,sum)){
flag=;
}
}
}
if(flag){
printf("Twin snowflakes found.\n");
}else{
printf("No two snowflakes are alike.\n");
}
} return ;
}

nyoj130 相同的雪花的更多相关文章

  1. NYOJ130 同样的雪花 【Hash】

    同样的雪花 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描写叙述 You may have heard that no two snowflakes are alike. ...

  2. 今天大雪 看雪花飘落HTML5特效

    今天大雪,弄一个下雪的特效.html5飘落的雪花堆积动画特效 查看效果:http://hovertree.com/texiao/js/snow.htm 以下是完整源代码,保存到HTML文件也可以看效果 ...

  3. CAEmitterLayer实现雪花效果

    CAEmitterLayer 简介 在iOS5.0中,Apple引入了CAEmitterLayer层,CAEmitterLayer是一个高性能的粒子效果引擎,被用来创建实时粒子动画,如:烟雾,火,雨等 ...

  4. 分析自定义view的实现过程-实现雪花飞舞效果(转载有改动)

    声明:本文源码出自实现雪花飞舞效果(有改动)主要通过这篇文来分析自定义view的实现过程. 没事时,比较喜欢上网看看一些新的东西,泡在网上的日子就是一个很不错的网站. 下面开始了,哈哈.^_^ 大家都 ...

  5. 虚幻引擎4笔记20160821 - 使用GPU粒子做雪花旋转镜头雪花忽有忽无的问题

    在使用GPU进行雪花制作的时候,雪花总是在镜头旋转的时候,一会有,一会无的情况,后来下载别人的例子才知道,原来要给粒子加上边界,具体解决方法如下图

  6. 《IT蓝豹》吹雪花demo,学习android传感器

    吹雪花demo,学习android传感器 吹雪花demo,学习android传感器,嘴巴对着手机底部吹一下就会出现飘着雪花效果. 算是学习android传感器效果.本例子主要是通过android.me ...

  7. web前端学习笔记---实现雪花飘落的效果

    看了javascript网页特效实例大全中的图片飘下的效果实例,觉得值得动手学习下. 就把图片改成雪花图,完成一个雪花飘下的效果. 并且,其中有些内容比较陈旧了,那么就学者改掉吧. 包括: 1.对le ...

  8. 使用javascript实现的雪花飞舞的效果

    原作者是在body中不停的插入多个小div雪花来向下慢慢飘,一直飘到body的底部后,将雪花移除,于是,将原来的代码稍加修改,让他只是从屏幕的顶部飘落到屏幕底部(不是body的底部)后,就将雪花移除, ...

  9. koch曲线与koch雪花的MATLAB实现

    代码 % -- function koch(Ax, Ay, Bx, By) % 控制递归深度 Deepth = ; % 控制图画大小 Size = ; + (By-Ay)^) < Deepth ...

随机推荐

  1. virtualBox下面安装linux系统如何共享目录

    背景: 系统是win+virtualBox 在虚拟机中安装了linuxMint系统. 如何共享目录呢 第一步: 在虚拟机中安装增强功能 2,在virtualBox中设置共享目录 3,在linux下创建 ...

  2. List之Union(),Intersect(),Except()

    http://www.cnblogs.com/qinpengming/archive/2012/12/03/2800202.html List之Union(),Intersect(),Except() ...

  3. 关于JS的几点TIPS

    作为前端基本工作每天都会用到JS...但是我们对JS真的都了解吗,或者说有什么tips是我们不知道的呢.. So..此文关于JS的几点tips..... 一:定时器(可传多个参数) 首先是一个一般的定 ...

  4. Maven初级学习(三)常用命令

    依赖关系查看 mvn dependency:list #列表形式展示依赖 mvn dependency:tree #层级关系展示依赖 mvn dependency:analyze #依赖分析 声明周期 ...

  5. Maven初级学习(一)手把手教你Maven安装

    序:学习安装Maven,在Windows和Unix系统上. 一.Windows系统安装MVN 前提正确安装JDK1.5以上的版本 1 下载最先版Mvn http://maven.opache.org/ ...

  6. 解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX

    从网上抓了一些字节流,想打印出来结果发生了一下错误: UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position ...

  7. 如何在发布博客时插入复杂公式——Open Live Writer

    1.http://latex.codecogs.com/eqneditor/editor.php 2.使用Word发布

  8. 打开Excel的报错,提示:不能使用对象链接和嵌入

    计算机这几天在打开Excel文档的时候,提示:不能使用对象链接和嵌入, 而且出现如下的提示:Microsoft Office Excel进程已停止工作, 每次打开Excel的时候都是同样的问题,害我跟 ...

  9. python下载网页源码 写入文本

    import urllib.request,io,os,sysreq=urllib.request.Request("http://echophp.sinaapp.com/uncategor ...

  10. Support for Xpm library: no问题

    编译gd,出现问题 Support for Xpm library:          no 怎么解决? 解决办法就是去下载libXpm库安装: yum -y install libXpm-dev 这 ...