Snowflake Snow Snowflakes - poj 3349 (hash函数)
判断n朵雪花中,是否有完全一样的雪花。简单的hash,将雪花的六个边的权值加起来,记为sum,将sum相等的雪花归为一类,再在这里面根据题意找完全相同的,判断顺时针或者逆时针的所有角是否一模一样。
#include<vector>
#include<stdio.h>
int MOD=;
std::vector<int> snow[];
int arm[][];
int isSame(int s1,int s2){
for(int i=;i<;i++){
int flag=;
for(int j=,k=i;j<;j++,k=(k+)%){
if(arm[s1][j]!=arm[s2][k]){
flag=;
break;
}
}
if(flag) return ;
}
for(int i=;i<;i++){
int flag=;
for(int j=,k=i;j>=;j--,k=(k+)%){
if(arm[s1][j]!=arm[s2][k]){
flag=;
break;
}
}
if(flag) return ;
}
return ;
}
int main() {
int N;
scanf("%d",&N);
int flag=;
for(int i=;i<N;i++){
int sum=;
for(int j=;j<;j++){
scanf("%d",&arm[i][j]);
sum+=arm[i][j];
}
if(flag)
continue;
sum=sum%MOD;
for(int j=;j<snow[sum].size();j++){
flag=isSame(snow[sum][j],i);
if(flag)
break;
}
snow[sum].push_back(i);
}
if(flag)
printf("Twin snowflakes found.\n");
else
printf("No two snowflakes are alike.\n");
return ;
}
附:
Time Limit: 4000MS | Memory Limit: 65536K | |
Total Submissions: 34732 | Accepted: 9119 |
Description
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.
Input
The first line of input 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.
Output
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.
Sample Input
2
1 2 3 4 5 6
4 3 2 1 6 5
Sample Output
Twin snowflakes found.
Snowflake Snow Snowflakes - poj 3349 (hash函数)的更多相关文章
- Snowflake Snow Snowflakes POJ - 3349 Hash
题意:一个雪花有六个角 给出N个雪花 判断有没有相同的(可以随意旋转) 参考:https://blog.csdn.net/alongela/article/details/8245005 注意:参考 ...
- Snowflake Snow Snowflakes POJ - 3349(hash)
You may have heard that no two snowflakes are alike. Your task is to write a program to determine wh ...
- POJ--3349 Snowflake Snow Snowflakes(数字hash)
链接:Snowflake Snow Snowflakes 判断所有的雪花里面有没有相同的 每次把雪花每个角的值进行相加和相乘 之后hash #include<iostream> #incl ...
- 【POJ3349 Snowflake Snow Snowflakes】【Hash表】
最近在对照省选知识点自己的技能树 今天是Hash 题面 大概是给定有n个6元序列 定义两个序列相等 当两个序列各自从某一个元素开始顺时针或者逆时针旋转排列能得到两个相同的序列 求这n个6元序列中是否有 ...
- POJ 3349:Snowflake Snow Snowflakes(数的Hash)
http://poj.org/problem?id=3349 Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K T ...
- POJ 3349 Snowflake Snow Snowflakes (Hash)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 48646 Accep ...
- POJ 3349 Snowflake Snow Snowflakes
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 27598 Accepted: ...
- 哈希—— POJ 3349 Snowflake Snow Snowflakes
相应POJ题目:点击打开链接 Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions ...
- POJ 3349 Snowflake Snow Snowflakes(简单哈希)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 39324 Accep ...
随机推荐
- java-继承-类变量与实例变量
父类中的类的变量(静态属性)与其子类共享一份. 父类中的实例变量与其子类各自维护各自的.
- Android 架构 3.实现
以实现最小化可用产品(MVP)的目标,用最简单的方式来搭建架构和实现代码.IDE采用Android Studio,Demo实现的功能为用户注册.登录和展示一个券列表,数据采用我们现有项目的测试数据,接 ...
- 破解SQLServer for Linux预览版的3.5GB内存限制 (RHEL篇) 转
https://www.ancii.com/database/30842.html 微软发布了SQLServer for Linux,但是安装竟然需要3.5GB内存,这让大部分云主机用户都没办法尝试这 ...
- 关于 modelNameLike 查询无数据
---恢复内容开始--- 1.今天在测试的时候发现 model中的name不能模糊查询. ModelQuery modelQuery = repositoryService.createModelQu ...
- 怎样用bat批量重命名文件夹和文件
很早以前本人写过重命名文件夹的文章,发现其中稍有不完善的地方,其主要功能在文件夹名前统一加上字符,或者在文件夹名后统一加上字符,有网友反应功能太单一.今天我又仔细研究了一下bat批处理代码,分别能完全 ...
- linux systemctl service examples
一.脚本服务化目的 1.python 在 文本处理中有着广泛的应用,为了满足文本数据的获取,会每天运行一些爬虫抓取数据.但是网上买的服务器会不定时进行维护,服务器会被重启.这样我们的爬虫服务就无法运行 ...
- HTTP—缓存
1. ETag HTTP 1.1中引入了ETag来解决缓存的问题.ETag全称是Entity Tag,由服务端生成,服务端可以决定它的生成规则.如果根据文件内容生成散列值.那么条件请求将不会受到时间戳 ...
- 【AS3 Coder】任务九:游戏新手引导的制作原理(上)
使用框架:AS3任务描述:了解游戏中新手的制作原理及流程 难度:3 本章源码下载:http://www.iamsevent.com/zb_users/UPLOAD/GuideManager/Test1 ...
- Scala实现冒泡排序、归并排序和快速排序
1.冒泡排序 def sort(list: List[Int]): List[Int] = list match { case List() => List() case head :: tai ...
- (转)spring boot实战(第六篇)加载application资源文件源码分析
原文:http://blog.csdn.net/liaokailin/article/details/48878447