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 ...
随机推荐
- gitk图形界面中文乱码情况
当打开gitk图形界面时,文件中的中文部分乱码了,这大部分是因为编码格式的问题,为了跟上时代的脚步,本人建议都是用utf-8编码. 为了方便,我将全局配置为utf-8编码: git config -- ...
- 开发板无法ping通虚拟机的问题解决一例
先描述一下遇到的问题: 使用的开发板是Tq2440,我将虚拟机和开发板都设在在了同一个网段,并且虚拟机使用的是桥接的方式,我用nfs的方式挂载根文件系统是失败,系统无法起来,后来我进入uboot命令模 ...
- SublimeText3插件Emmet自定义HTML
工作上总使用Sublime,Emmet默认生成html格式不太满足需要,生成后还需要额外添加一些元素,如下是自定义html格式的步骤,供大家参考: 1. 安装Sublime Text3.Emmet插件 ...
- Linq 简明教程
一个简单的实例 static void Main(string[] args) { string[] names = { "Alonso", "Zheng", ...
- Shell实现多级菜单系统安装维护脚本实例分享
Shell实现多级菜单系统安装维护脚本实例分享 这篇文章主要介绍了Shell实现多级菜单系统安装维护脚本实例分享,本文脚本用多级菜单实现管理WEB服务器.Mysql服务器.Nginx服器等,需要的朋友 ...
- PHP addslashes() 函数
定义和用法 addslashes() 函数在指定的预定义字符前添加反斜杠. 这些预定义字符是: 单引号 (') 双引号 (") 反斜杠 (\) NULL 语法 addslashes(stri ...
- CMD/AMD的原理、区别和应用
有必要简单提一下两者的主要区别: 1.CMD推崇依赖就近,可以把依赖写进你的代码中的任意一行,例: define(function(require, exports, module) { var a ...
- 【C/C++学院】0831-类与对象的异常/面试100题1-100
类与对象的异常 Cpp异常 #include <iostream> #include <string.h> using namespace std; //标识错误的类型 cla ...
- DirectShow控制台输出和保存视频设备名称
#include "windows.h" #include "TCHAR.h" #include <dshow.h> #include <ve ...
- Linux——解决RedHat6/CentOS6系统中“弹出界面eth0:设备似乎不存在”的问题
刚刚在自己的CentOS6系统中执行service network restart时,竟然提示: 弹出界面 eth0: 设备 似乎不存在, 初始化操作将被延迟. [失败] 这事可真神奇.于是手动编 ...