相同的雪花

时间限制: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. Myeclipse如何关联源码

    Myeclipse版本:Myeclipse2014 关联源码前要下载对应的源码,如本例的dom4j-1.6.1.jar,则去下载对应的源码dom4j-1.6.1.zip 如果做的是web项目,就要将该 ...

  2. web网页颜色色谱

    snow 255 250 250 #fffafa ghostwhite 248 248 255 #f8f8ff whitesmoke 245 245 245 #f5f5f5 gainsboro 220 ...

  3. Java-开启Java之路

    .NET还是我的最爱··· 准备学习下底层知识,为Java打打基础, 然后开始正式学习Java, 也算是曲线救国了, Go,Go,Go ... 二〇一六年十一月十日 18:09:54

  4. spring学习

    http://blog.csdn.net/chjttony/article/details/6301523 http://blog.csdn.net/chjttony/article/details/ ...

  5. ServiceManager: Permmission failure: android.permission.RECORD_AUDIO

    今天在Android6.0系统的手机上测试一款APP,出现如题错误: ServiceManager: Permmission failure: android.permission.RECORD_AU ...

  6. 【python网络编程】使用rsa加密算法模块模拟登录新浪微博

    一.基础知识 http://blog.csdn.net/pi9nc/article/details/9734437 二.模拟登录 因为上学期参加了一个大数据比赛,需要抓取数据,所以就想着写个爬虫抓取新 ...

  7. 采用Atlas+Keepalived实现MySQL读写分离、读负载均衡【转载】

      文章 原始出处 :http://sofar.blog.51cto.com/353572/1601552 ============================================== ...

  8. javascript高级程序设计---Event对象三

    进度事件 进度事件用来描述一个事件进展的过程,比如XMLHttpRequest对象发出的HTTP请求的过程.<img>.<audio>.<video>.<st ...

  9. VB .NET周期实现

    这里仅提供一个方案,当然会有比本方案更好的,欢迎提供. 简介 在vb.net实现周期调度的问题时(就是间隔固定的时间做什么事情),我们最先想到的一定是(反正我是)利用timer(定时器)来做这个计时的 ...

  10. 使用shell脚本自动化对硬盘进行分区

    在Linux系统中,可以使用fdisk 对硬盘进行分区,但是要手动执行很多命令,这样使用有很麻烦,现在记一个用fdisk 的脚本自动执行. #make partition dd count= fdis ...