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 ...
随机推荐
- Eclipse Action
Interface IAction package org.eclipse.jface.action; import org.eclipse.core.commands.IHandlerAttribu ...
- 类型信息(RTTI和反射)——反射
运行时类型信息可以让你在程序运行时发现和使用类型信息. 在Java中运行时识别对象和类的信息有两种方式:传统的RTTI,以及反射.下面就来说说反射. 重点说说通过反射获取方法以及调用方法,即类方法提取 ...
- GitLab 的安装及汉化
系统环境:CentOS7 切记:安装GitLab 时会自动安装GitLab自带的Nginx,为了避免冲突,部署环境时先不要安装Nginx. 官网安装及汉化安装 官网安装最新版GitLab:https: ...
- April 10 2017 Week 15 Monday
He alone is poor who does not possess knowledge. 没有知识,才是贫穷. Knowledge, as a important part of wisdom ...
- Git-进阶-远程仓库的使用
一.远程仓库怎么玩 1. 自己搭建一个运行Git的服务器 Git是分布式版本控制系统,同一个Git仓库,可以分布到不同的机器上,但肯定有一台机器有着最原始的版本库,然后别的机器来克隆这个原始版本库,这 ...
- vuejs给组件绑定原生事件
给组件绑定事件,该事件是自定义的事件 <div id='root'> <child @click='handleClick'></child> </div&g ...
- Spring Security 实现手机验证码登录
思路:参考用户名密码登录过滤器链,重写认证和授权 示例如下(该篇示例以精简为主,演示主要实现功能,全面完整版会在以后的博文中发出): 由于涉及内容较多,建议先复制到本地工程中,然后在细细研究. 1. ...
- Linux下C程序进程地址空间布局[转]
我们在学习C程序开发时经常会遇到一些概念:代码段.数据段.BSS段(Block Started by Symbol) .堆(heap)和栈(stack).先看一张教材上的示意图(来源,<UNIX ...
- Javascript Ajax 请求
var XMLHttpReq; function createXMLHttpRequest() { try { XMLHttpReq = new ActiveXObject("Msxml2. ...
- 循环语句:LOOP,WHILE和数字式循环
一 简单循环 1 语法: LOOP 要执行的语句; EXIT WHEN <条件语句> --条件满足,退出循环语句 END LOOP; 2 例子: DECLARE ...