POJ3349 Language: Snowflake Snow Snowflakes

POJ3349 Language: Snowflake Snow Snowflakes

题目:传送门



题解:

   链表+hash的一道水题

   填个坑补个漏...

  



代码:

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cstdlib>
 4 #include<cmath>
 5 #include<algorithm>
 6 using namespace std;
 7 typedef long long LL;
 8 int n,tot,mod=99991;
 9 int a[10],snow[110000][10],head[110000],next[110000];
10 int Hash(int *a) {
11     int sum=0,ans=1;
12     for(int i=0;i<6;i++) {
13         sum=(sum+a[i])%mod;
14         ans=(LL)ans*a[i]%mod;
15     }
16     return (sum+ans)%mod;
17 }
18 bool Find(int *a,int *b) {
19     for(int i=0;i<6;i++)
20         for(int j=0;j<6;j++) {
21             bool bk=true;
22             for(int k=0;k<6;k++)if(a[(i+k)%6]!=b[(j+k)%6])bk=false;
23             if(bk)return true;
24             bk=true;
25             for(int k=0;k<6;k++)if(a[(i+k)%6]!=b[(j-k)%6])bk=false;
26             if(bk)return true;
27         }
28     return false;
29 }
30 bool pd(int *a) {
31     int x=Hash(a);
32     for(int i=head[x];i;i=next[i])if(Find(snow[i],a))return true;
33     ++tot;
34     for(int i=0;i<6;i++)snow[tot][i]=a[i];
35     next[tot]=head[x];
36     head[x]=tot;
37     return false;
38 }
39 int main() {
40     scanf("%d",&n);tot=0;
41     for(int i=1;i<=n;i++) {
42         for(int j=0;j<6;j++)scanf("%d",&a[j]);
43         if(pd(a)) {
44             printf("Twin snowflakes found.");
45             return 0;
46         }
47     }
48     printf("No two snowflakes are alike.");
49     return 0;
50 }

原文地址:https://www.cnblogs.com/CHerish_OI/p/8871995.html

时间: 2024-10-11 04:52:13

POJ3349 Language: Snowflake Snow Snowflakes的相关文章

poj3349(Snowflake Snow Snowflakes)

题目地址:Snowflake Snow Snowflakes 题目大意: 给你N个雪花,每个雪花由6个长度构成,让你判断N哥雪花中是否有两个或两个以上的雪花是相似的,相似的规则是:有两个雪花a.b.b在任意位置顺时针或者逆时针转和a的大小顺序相同即为相似的雪花. 解题思路: 一般的方法如果时间复杂度是O(n^2)的都会超时,所以要尽量让N小,所有用个简单哈希.将6个数的和对N取余存到一个vector.然后再在vector里找看是否有相似的雪花. 代码: 1 #include <algorithm

[poj3349]Snowflake Snow Snowflakes(hash)

Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 37615 Accepted: 9882 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

POJ3349 Snowflake Snow Snowflakes (hash

Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 48624   Accepted: 12697 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.

poj 3349:Snowflake Snow Snowflakes(哈希查找,求和取余法+拉链法)

Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 30529   Accepted: 8033 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. Y

hash应用以及vector的使用简介:POJ 3349 Snowflake Snow Snowflakes

今天学的hash.说实话还没怎么搞懂,明天有时间把知识点总结写了,今天就小小的写个结题报告吧! 题意: 在n (n<100000)个雪花中判断是否存在两片完全相同的雪花,每片雪花有6个角,每个角的长度限制为1000000 两片雪花相等的条件: 雪花6个角的长度按顺序相等(这个顺序即可以是顺时针的也可以是逆时针的) 解题思路: hash:连加求余法 求key 值,链地址法解决冲突,连加求余法 求key 值挺简单,关于链地址法解决冲突可以通过c++中,vector容器可以较为方便的实现. 下面先介绍

[ACM] POJ 3349 Snowflake Snow Snowflakes(哈希查找,链式解决冲突)

Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 30512   Accepted: 8024 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. Y

POJ 3349:Snowflake Snow Snowflakes(数的Hash)

http://poj.org/problem?id=3349 Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 37609   Accepted: 9878 Description You may have heard that no two snowflakes are alike. Your task is to write a program to determine

哈希—— POJ 3349 Snowflake Snow Snowflakes

相应POJ题目:点击打开链接 Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 33595   Accepted: 8811 Description You may have heard that no two snowflakes are alike. Your task is to write a program to determine whether this is

POJ 3349 Snowflake Snow Snowflakes (哈希表)

题意:每片雪花有六瓣,给出n片雪花,六瓣花瓣的长度按顺时针或逆时针给出,判断其中有没有相同的雪花(六瓣花瓣的长度相同) 思路:如果直接遍历会超时,我试过.这里要用哈希表,哈希表的关键码key用六瓣花瓣的长度的和取余一个数得到,表中为雪花的存储位置address(即在snowflakes数组中的位置) 代码: #include<iostream> #include<vector> using namespace std; const int maxn=100000+100;//雪花最