nyoj130 相同的雪花
相同的雪花
- 描述
- 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 相同的雪花的更多相关文章
- NYOJ130 同样的雪花 【Hash】
同样的雪花 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描写叙述 You may have heard that no two snowflakes are alike. ...
- 今天大雪 看雪花飘落HTML5特效
今天大雪,弄一个下雪的特效.html5飘落的雪花堆积动画特效 查看效果:http://hovertree.com/texiao/js/snow.htm 以下是完整源代码,保存到HTML文件也可以看效果 ...
- CAEmitterLayer实现雪花效果
CAEmitterLayer 简介 在iOS5.0中,Apple引入了CAEmitterLayer层,CAEmitterLayer是一个高性能的粒子效果引擎,被用来创建实时粒子动画,如:烟雾,火,雨等 ...
- 分析自定义view的实现过程-实现雪花飞舞效果(转载有改动)
声明:本文源码出自实现雪花飞舞效果(有改动)主要通过这篇文来分析自定义view的实现过程. 没事时,比较喜欢上网看看一些新的东西,泡在网上的日子就是一个很不错的网站. 下面开始了,哈哈.^_^ 大家都 ...
- 虚幻引擎4笔记20160821 - 使用GPU粒子做雪花旋转镜头雪花忽有忽无的问题
在使用GPU进行雪花制作的时候,雪花总是在镜头旋转的时候,一会有,一会无的情况,后来下载别人的例子才知道,原来要给粒子加上边界,具体解决方法如下图
- 《IT蓝豹》吹雪花demo,学习android传感器
吹雪花demo,学习android传感器 吹雪花demo,学习android传感器,嘴巴对着手机底部吹一下就会出现飘着雪花效果. 算是学习android传感器效果.本例子主要是通过android.me ...
- web前端学习笔记---实现雪花飘落的效果
看了javascript网页特效实例大全中的图片飘下的效果实例,觉得值得动手学习下. 就把图片改成雪花图,完成一个雪花飘下的效果. 并且,其中有些内容比较陈旧了,那么就学者改掉吧. 包括: 1.对le ...
- 使用javascript实现的雪花飞舞的效果
原作者是在body中不停的插入多个小div雪花来向下慢慢飘,一直飘到body的底部后,将雪花移除,于是,将原来的代码稍加修改,让他只是从屏幕的顶部飘落到屏幕底部(不是body的底部)后,就将雪花移除, ...
- koch曲线与koch雪花的MATLAB实现
代码 % -- function koch(Ax, Ay, Bx, By) % 控制递归深度 Deepth = ; % 控制图画大小 Size = ; + (By-Ay)^) < Deepth ...
随机推荐
- recording just for inquiry in the future
auditd审计 相关命令有: auditd, auditctl, ausearch, aureport 相关文件: /etc/audit/auditd.conf, /etc/audit/audit. ...
- Netbeans 设置模板
/** * @Description * @author ${user} * @date ${date} ${time} * @copyright ${copyright} */ 工具-->模板 ...
- 工作中一个简单的shell程序
下面是工作中用到的链接数据库的shell程序. #!/bin/bash ] ; then echo "prase is wrong ,please check first" exi ...
- shell学习之路:流程控制(if)
1.单分支if条件语句 if [ 条件判断式 ];then 程序 fi 或者 if [ 条件判断式 ] then 程序 fi 注意事项: 1.if语句使用fi结尾,和一般语言使用大括号结尾不同 2.[ ...
- PHP mkdir()无写权限的问题解决方法
这篇文章主要介绍了PHP mkdir()无写权限的问题解决方法,对umask做了详细解释以及mkdir()后没写权限的解决方法,需要的朋友可以参考下 使用mkdir创建文件夹时,发现这个函数有两个 ...
- Properties类的使用方法
它提供了几个主要的方法: 1. getProperty ( String key),用指定的键在此属性列表中搜索属性.也就是通过参数 key ,得到 key 所对应的 value. 2. load ( ...
- sql中的常见的全局变量
select APP_NAME ( ) as w --当前会话的应用程序 select @@IDENTITY --返回最后插入的标识值 select USER_NAME() --返回用户数据库用户名 ...
- Inside the c++ object module 阅读摘要
这本书是 Stanley B. Lippman于1996年所写,而最早的c++标准是 ISO/IEC 14882:1998[18],即C++98. Chapter 1: Object Lessons ...
- linux系统安装yum环境
http://blog.sina.com.cn/s/blog_63d8dad80101cn2s.html 1.卸载rhel的默认安装的yum包 查看yum包 rpm -qa|grep yum 卸载之 ...
- maven 工程启动找不到 Spring ContextLoaderListener 的解决办法
1.错误: Error configuring application listener of class org.springframework.web.context.ContextLoader ...