Snowflake Snow Snowflakes【Poj3349】
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.
Source
题解:
哈希,个人理解哈希就是一种暴力手法,选出符合要求的情况
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN=1e5+10;
const int MAXM=1e6;
const int pri=999983;
struct node{
int a[6];
}x[MAXN];
vector<int >G[MAXM];
inline bool scan_d(int &num)
{
char in;bool IsN=false;
in=getchar();
if(in==EOF) return false;
while(in!='-'&&(in<'0'||in>'9')) in=getchar();
if(in=='-'){ IsN=true;num=0;}
else num=in-'0';
while(in=getchar(),in>='0'&&in<='9'){
num*=10,num+=in-'0';
}
if(IsN) num=-num;
return true;
}
int main()
{
int n;
scanf("%d",&n);
int flag=0,MAX=0;
for (int i = 0; i <n ; ++i) {
for (int j = 0; j <6 ; ++j) {
scan_d(x[i].a[j]);
}
int z=0;
z=((x[i].a[0]+x[i].a[2]+x[i].a[4])&(x[i].a[1]+x[i].a[3]+x[i].a[5]))%pri;//此处还可以是,(a[0]+...+a[5])%pir
G[z].push_back(i);
}
int cnt=0;
for (int i = 0; i <=pri ; ++i) {
if(G[i].size()>=2)
{
for (int k = 0; k <G[i].size()-1 ; ++k) {
for (int l = k+1; l <G[i].size() ; ++l) {
for (int s=0;s<6;s++)//顺时针
{
cnt=0;
for (int j = 0,z=0; z<6,j <6 ; ++j,z++)
{
if(x[G[i][k]].a[j]!=x[G[i][l]].a[(z+s)%6])
{
cnt=1;
break;
}
}
if(cnt==0)
{
flag=1;
goto out;
}
}
for (int s=0;s<6;s++)//逆时针
{
cnt=0;
for (int j = 0,z=5; z>=0,j <6 ; ++j,z--)
{
if(x[G[i][k]].a[j]!=x[G[i][l]].a[(z-s+6)%6])
{
cnt=1;
break;
}
}
if(cnt==0)
{
flag=1;
goto out;
}
}
}
}
}
}
out:
if(flag)
{
printf("Twin snowflakes found.\n");
} else
printf("No two snowflakes are alike.\n");
return 0;
}
Snowflake Snow Snowflakes【Poj3349】的更多相关文章
- poj3349 Snowflake Snow Snowflakes【HASH】
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 49991 Accep ...
- POJ3349 Snowflake Snow Snowflakes 【哈希表】
题目 很简单,给一堆6元组,可以从任意位置开始往任意方向读,问有没有两个相同的6元组 题解 hash表入门题 先把一个六元组的积 + 和取模作为hash值,然后查表即可 期望\(O(n)\) #inc ...
- POJ3349 Language: Snowflake Snow Snowflakes
POJ3349 Language: Snowflake Snow Snowflakes 题目:传送门 题解: 链表+hash的一道水题 填个坑补个漏... 代码: #include<cstdio ...
- [poj3349]Snowflake Snow Snowflakes(hash)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 37615 Accepted: ...
- POJ--3349 Snowflake Snow Snowflakes(数字hash)
链接:Snowflake Snow Snowflakes 判断所有的雪花里面有没有相同的 每次把雪花每个角的值进行相加和相乘 之后hash #include<iostream> #incl ...
- POJ3349 Snowflake Snow Snowflakes (hash
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 48624 Accep ...
- POJ 3349 Snowflake Snow Snowflakes(简单哈希)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 39324 Accep ...
- Snowflake Snow Snowflakes(哈希表的应用)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 27312 Accep ...
- poj 3349:Snowflake Snow Snowflakes(哈希查找,求和取余法+拉链法)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 30529 Accep ...
随机推荐
- html 01前沿-web介绍
1. 认识网页 网页主要由文字.图像和超链接等元素构成.当然,除了这些元素,网页中还可以包含音频.视频以及Flash等. 2. 浏览器(显示代码) 浏览器是网页显示.运行的平台,常用的浏览器有IE.火 ...
- <Android 基础(十七)> ViewPager介绍
介绍 Layout manager that allows the user to flip left and right through pages of data. You supply an i ...
- 栅格那点儿事(四E)
栅格金字塔 如果上面的部分都已经看过了,那么如何在ArcMap中更好的渲染一个栅格数据你已经知道了.可仅展示好一个栅格数据是不够的,我们还需要知道如何快速的展示一个栅格数据. 讲金字塔之前,先解释 ...
- 使用QJM实现HDFS的HA配置
使用QJM实现HDFS的HA配置 1.背景 hadoop 2.0.0之前,namenode存在单点故障问题(SPOF,single point of failure),如果主机或进程不可用时,整个集群 ...
- linux挂载和卸载NAS操作
1.建立准备挂载NFS的目录,例如:cd /home/test,mkdir my_NFS_Catalog 2.挂接NFS至 /home/test/my_NFS_Catalog目录下(nas有两种格式: ...
- 如何在windows下运行Linux命令?(转载)
在windows上可以运行或使用linux下面的命令吗?可以,小编今天就来分享怎么样让Windows支持Linux命令,做这些安装和设置后,就可以非常方便的在windows系统中使用linux下面的命 ...
- LCA最近公共祖先(POJ1330)
题目链接:http://poj.org/problem?id=1330 解题报告: 先将一个子节点,深搜每一个根节点,并标记. 然后深索另一个子节点,当发现访问过了,就找到了最近的公共祖先. #inc ...
- DOM节点(二):操作节点
appendChild() 用于向childNodes列表的末尾添加一个节点. var returnedNode = someNode.appendChild(newNode); 如果传入的节点已经是 ...
- redis hash类型
- lasagne保存网络参数
# Optionally, you could now dump the network weights to a file like this: # np.savez('model.npz', *l ...