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 ...
随机推荐
- atom markdown转换PDF 解决AssertionError: html-pdf: Failed to load PhantomJS module
atom编辑器markdown转换PDF 解决AssertionError: html-pdf: Failed to load PhantomJS module. You have to set th ...
- Design Pattern ->Factory Method
Layering & Contract Philosophy With additional indirection Factory Method The example code is as ...
- python模块详解 XML
XML模块 XML是实现不同语言或程序之间进行数据交换的协议,和json一样. XML格式: <?xml version="1.0" encoding="UTF-8 ...
- April 9 2017 Week 15 Sunday
In the evening one may praise the day. 入夜方能赞美白昼. I think that could be understand in different ways, ...
- golang实现文件上传权限验证(超简单)
Go语言创建web server非常简单,部署也很容易,不像IIS.Apache等那么重量级,需要各种依赖.配置.一些功能单一的web 服务,用Go语言开发特别适合.http文件上传下载服务,在很多地 ...
- cesium 动态水面效果
后续继续更新
- postman 1—官网下载及安装
测试过程中构造批量数据方式: 1 业务只关联数据库单张表,那么可以通过sql插入数据 也可以通过接口构造. 2 业务关联多张数据库表.要在多张表插入数据且保持数据的一致性,此时通过接口批量发送请求构造 ...
- IOS 自定义代理delegate方法
创建一个自定义代理 @class MJTgFooterView; /** 1.协议名称: 控件类名 + Delegate 2.代理方法普遍都是@optional 3. */ @protocol MJT ...
- Linux 源码安装MariaDB 10.0.16
cmake软件 tar -zxvf cmake-2.8.8.tar.gz cd cmake-2.8.8 ./bootstrap make && make install 依 ...
- UML总结:UML用于建模描述结构和行为
UML有3种基本的构造块:组件.关系和图 我们将 UML 中的图分为两大类: 结构图 行为图 (1)结构建模: 结构建模具有捕捉静态的功能,包括下列各项: 类图 对象图 组件图 部署图 结构模型代表的 ...