相同的雪花

时间限制: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. 1
  2. 2
  3. 1 2 3 4 5 6
  4. 4 3 2 1 6 5
样例输出
  1. Twin snowflakes found.

解题思路:用到哈希的知识,通过观察可以发现,如果是两片相同的雪花,那么他的和一定是相同的,那就把和当做它的地址来存储,然后如果和相同就都连接在相应的和的后面,采用的是链地址法,然后再从和相同的里面来寻找相同的雪花,就大大的减少了比较次数。

代码:

  1. #include <iostream>
  2. #include <cstdio>
  3.  
  4. using namespace std;
  5.  
  6. typedef struct snow{
  7. int a[];
  8. snow *next;
  9. };
  10. snow *s[];
  11.  
  12. int fin(int b[],int sum){
  13. snow *p;
  14. p=s[sum]->next;
  15. while(p){
  16. for(int i=;i<;i++){
  17. int j;
  18. if(b[i]==p->a[]){
  19. for(j=;j<;j++){
  20. if(b[i+j]%!=p->a[j]){
  21. break;
  22. }
  23. }
  24. if(j==){
  25. return ;
  26. }
  27. for(j=;j<;j++){
  28. if(b[((i-j%+)%)]!=p->a[j]){
  29. break;
  30. }
  31. }
  32. if(j==){
  33. return ;
  34. }
  35. }
  36. }
  37. p=p->next;
  38. }
  39. p=new snow;
  40. for(int i=;i<;i++){
  41. p->a[i]=b[i];
  42. }
  43. p->next=s[sum]->next;
  44. s[sum]->next=p;
  45. return ;
  46. }
  47.  
  48. int main()
  49. {
  50. int n;
  51. int t;
  52. int b[];
  53. int sum;
  54. int flag;
  55. scanf("%d",&n);
  56. for(int i=;i<;i++){
  57. s[i]=new snow;
  58. s[i]->next=NULL;
  59. }
  60. while(n--){
  61. scanf("%d",&t);
  62. flag=;
  63. for(int i=;i<t;i++){
  64. sum=;
  65. for(int j=;j<;j++){
  66. scanf("%d",&b[j]);
  67. sum+=b[j];
  68. }
  69. sum%=;
  70. if(!flag){
  71. if(fin(b,sum)){
  72. flag=;
  73. }
  74. }
  75. }
  76. if(flag){
  77. printf("Twin snowflakes found.\n");
  78. }else{
  79. printf("No two snowflakes are alike.\n");
  80. }
  81. }
  82.  
  83. return ;
  84. }

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. unzip 命令使用

    http://blog.sina.com.cn/s/blog_6c9d65a10100nzqf.html unzip命令:解压缩文件 他是解压zip压缩的文件,和zip互逆的一对工具.   命令: u ...

  2. objective-c与c++的差异

    oc的编译指令为 clang -fobjc-arc -framework Foundation test.m -o test oc中,1表示YES,0表示NO.并不是非0值都是YES,这是因为BOOL ...

  3. ASP.NET 大文件下载的实现思路及代码

    文件下载是一个网站最基本的功能,ASP.NET网站的文件下载功能实现也很简单,但是如果遇到大文件的下载而不做特殊处理的话,那将会出现不可预料的后果.本文就基于ASP.NET提供大文件下载的实现思路及代 ...

  4. EF-在EF中运行sql语句

    DbRawSqlQuery<int> result2 = db.Database.SqlQuery<int>("SELECT count(*) FROM test.s ...

  5. [C++基础]关于对象的创建及内存分配

    测试: #include <stdio.h>#include <QDebug> class KPoint{public: KPoint(int x, int y){ nx = ...

  6. VMware 关闭虚拟机 Ubuntu 12 的 3D 效果,提高性能

    Ubuntu 2012,有 2D 和 3D 的渲染效果,但是 在虚拟机中,开启 3D 效果后,特别卡.好在 VMware 中有个“关闭3D”的开关,如下图所示: 去掉勾选“加速 3D 图形”

  7. ajax状态

    ajax的几个状态 Uninitialized 初始化状态.XMLHttpRequest 对象已创建或已被 abort() 方法重置. Open open() 方法已调用,但是 send() 方法未调 ...

  8. javaweb框架构想-自己的对象存储池-遁地龙卷风

    设计初衷: 网站在提供服务的过程中,会创建很多对象,bean,dao层的对象尤为频繁,然而这些对象是可以重复利用的.设计思路: 对象连接池ObjectPool才用单态的设计模式,自带线程,每隔一段时间 ...

  9. java中重载与重写的区别

    (1) 方法重载是让类以统一的方式处理不同类型数据的一种手段.多个同名函数同时存在,具有不同的参数个数/类型. 重载Overloading是一个类中多态性的一种表现. 然后我们再来谈谈 重写(Over ...

  10. 在Fedora 20 上安装Mysql并初始化root密码

    [root@localhost ~]# yum -y install community-mysql-server #安装数据库 已加载插件:langpacks, refresh-packagekit ...