POJ 3349 Snowflake Snow Snowflakes (Hash)
Time Limit: 4000MS | Memory Limit: 65536K | |
Total Submissions: 48646 | Accepted: 12703 |
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. 思路:
虽然过了---但是代码是错的。
这是由于,我考虑的雪花相同,就是6个臂在不考虑相对位置的条件下,完全相同。这样可行,都是discuss告诉我的。。
不过,如果改成题意相同的样子,也只需要更改一下Hash的方式就行了。
代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
typedef unsigned long long ll;
const int maxn = 100009;
ll num[8],seed=9371;
ll state[maxn];
int Head[maxn],Next[maxn];
int main()
{
int n;
scanf("%lld",&n);
ll sum,ss;
int siz=0;
memset(Head,-1,sizeof(Head));
for(int i=1;i<=n;i++){
sum=0,ss=seed;
for(int j=1;j<=6;j++){
scanf("%lld",&num[j]);
}
sort(num+1,num+7);
for(int j=1;j<=6;j++){
sum+=ss*num[j];
ss*=ss;
}
int h=sum%maxn;
for(int i=Head[h];i!=-1;i=Next[i]){
if(state[i]==sum){printf("Twin snowflakes found.");return 0;}
}
state[++siz]=sum;
Next[siz]=Head[h];
Head[h]=siz;
}
printf("No two snowflakes are alike.");
}
POJ 3349 Snowflake Snow Snowflakes (Hash)的更多相关文章
- UVa 3349 Snowflake Snow Snowflakes(Hash)
http://poj.org/problem?id=3349 题意: 给出n片雪花留个角的长度,要求判断是否有一样的雪花. 思路: Hash表的应用. 首先将每个雪花所有角的总长计算出来,如果两片雪花 ...
- POJ 3349 Snowflake Snow Snowflakes(简单哈希)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 39324 Accep ...
- [ACM] POJ 3349 Snowflake Snow Snowflakes(哈希查找,链式解决冲突)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 30512 Accep ...
- poj 3349:Snowflake Snow Snowflakes(哈希查找,求和取余法+拉链法)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 30529 Accep ...
- POJ 3349 Snowflake Snow Snowflakes(哈希)
http://poj.org/problem?id=3349 题意 :分别给你n片雪花的六个角的长度,让你比较一下这n个雪花有没有相同的. 思路:一开始以为把每一个雪花的六个角的长度sort一下,然后 ...
- POJ 3349 Snowflake Snow Snowflakes (哈希表)
题意:每片雪花有六瓣,给出n片雪花,六瓣花瓣的长度按顺时针或逆时针给出,判断其中有没有相同的雪花(六瓣花瓣的长度相同) 思路:如果直接遍历会超时,我试过.这里要用哈希表,哈希表的关键码key用六瓣花瓣 ...
- POJ - 3349 Snowflake Snow Snowflakes (哈希)
题意:给定n(0 < n ≤ 100000)个雪花,每个雪花有6个花瓣(花瓣具有一定的长度),问是否存在两个相同的雪花.若两个雪花以某个花瓣为起点顺时针或逆时针各花瓣长度依次相同,则认为两花瓣相 ...
- POJ 3349 Snowflake Snow Snowflakes(哈希表)
题意:判断有没有两朵相同的雪花.每朵雪花有六瓣,比较花瓣长度的方法看是否是一样的,如果对应的arms有相同的长度说明是一样的.给出n朵,只要有两朵是一样的就输出有Twin snowflakes fou ...
- 哈希—— POJ 3349 Snowflake Snow Snowflakes
相应POJ题目:点击打开链接 Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions ...
随机推荐
- 使用urllib2+re爬取web网站
应用1,使用urllib2+re爬取淘宝网指定页面的所有图片
- Java使用RabbitMQ之整合Spring(消费者)
依赖包: <!--RabbitMQ集成spring--> <!-- https://mvnrepository.com/artifact/org.springframework.am ...
- python绝对路径和相对路径
转自https://blog.csdn.net/databatman/article/details/49453953 下面的路径介绍针对windows,其他平台的暂时不是很了解. 在编写的py文件中 ...
- jqGrid选中行、格式化、自定义按钮、隐藏
获取选择一行的id: var id=$('#jqGrid').jqGrid('getGridParam','selrow'); 获取选择多行的id: var ids=$('#jqGrid').jqGr ...
- Vue单文件组件
前面的话 本文将详细介绍Vue单文件组件 概述 在很多 Vue 项目中,使用 Vue.component 来定义全局组件,紧接着用 new Vue({ el: '#container '}) 在每个页 ...
- 自定义 ASP.NET Identity Data Model with EF
One of the first issues you will likely encounter when getting started with ASP.NET Identity centers ...
- model,map,MapAndVivew用于页面跳转时候使用的即跳转后才添加属性 这样再回调中无法使用 因为回调的前提是页面不调转;解决的方法是用responsewrite(普通的字符响应)
model,map,MapAndVivew用于页面跳转时候使用的即跳转后才添加属性 这样再回调中无法使用 因为回调的前提是页面不调转:解决的方法是用responsewrite
- IDM下载神器
破解版IDM 个人评价:基本上能满足日常下载需求,除bt.磁力外. 不管是在线视频, 还是音乐, 电子书, 统统都能下载, 还附有爬虫功能~~ 直接附链接: 百度云链接: https://pan.ba ...
- [NOIp2009] $Hankson$ 的趣味题
类型:数论 传送门:>Here< 题意:给出四个数$a_0,a_1,b_0,b_1$,求满足$gcd(x,a_0)=a_1,lcm(x,b_0)=b_1$的$x$的个数 解题思路 显然$a ...
- bzoj 3674: 可持久化并查集加强版 (启发式合并+主席树)
Description Description:自从zkysb出了可持久化并查集后……hzwer:乱写能AC,暴力踩标程KuribohG:我不路径压缩就过了!ndsf:暴力就可以轻松虐!zky:…… ...