POJ3349 Language: Snowflake Snow Snowflakes

题目:传送门


题解:

   链表+hash的一道水题

   填个坑补个漏...

  


代码:

 #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
int n,tot,mod=;
int a[],snow[][],head[],next[];
int Hash(int *a) {
int sum=,ans=;
for(int i=;i<;i++) {
sum=(sum+a[i])%mod;
ans=(LL)ans*a[i]%mod;
}
return (sum+ans)%mod;
}
bool Find(int *a,int *b) {
for(int i=;i<;i++)
for(int j=;j<;j++) {
bool bk=true;
for(int k=;k<;k++)if(a[(i+k)%]!=b[(j+k)%])bk=false;
if(bk)return true;
bk=true;
for(int k=;k<;k++)if(a[(i+k)%]!=b[(j-k)%])bk=false;
if(bk)return true;
}
return false;
}
bool pd(int *a) {
int x=Hash(a);
for(int i=head[x];i;i=next[i])if(Find(snow[i],a))return true;
++tot;
for(int i=;i<;i++)snow[tot][i]=a[i];
next[tot]=head[x];
head[x]=tot;
return false;
}
int main() {
scanf("%d",&n);tot=;
for(int i=;i<=n;i++) {
for(int j=;j<;j++)scanf("%d",&a[j]);
if(pd(a)) {
printf("Twin snowflakes found.");
return ;
}
}
printf("No two snowflakes are alike.");
return ;
}

POJ3349 Language: Snowflake Snow Snowflakes的更多相关文章

  1. [poj3349]Snowflake Snow Snowflakes(hash)

    Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 37615 Accepted: ...

  2. POJ--3349 Snowflake Snow Snowflakes(数字hash)

    链接:Snowflake Snow Snowflakes 判断所有的雪花里面有没有相同的 每次把雪花每个角的值进行相加和相乘 之后hash #include<iostream> #incl ...

  3. poj3349 Snowflake Snow Snowflakes【HASH】

    Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 49991   Accep ...

  4. POJ3349 Snowflake Snow Snowflakes (hash

    Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 48624   Accep ...

  5. POJ 3349 Snowflake Snow Snowflakes(简单哈希)

    Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 39324   Accep ...

  6. Snowflake Snow Snowflakes(哈希表的应用)

    Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 27312   Accep ...

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

    Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 30529   Accep ...

  8. POJ 3349 Snowflake Snow Snowflakes

    Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 27598 Accepted: ...

  9. POJ 3349:Snowflake Snow Snowflakes(数的Hash)

    http://poj.org/problem?id=3349 Snowflake Snow Snowflakes Time Limit: 4000MS   Memory Limit: 65536K T ...

随机推荐

  1. SQLServer2008 字符串函数一览表

    /* 字符串函数 (PS.索引都从1开始计算)*/ /* 指定字符(或字符串)A.字符串B.起始索引.获得A在B中的索引值.*/select Charindex('d','abcdefg',0) -- ...

  2. Unity引擎GUI之Button

    UGUI Button,可以说是真正的使用最广泛.功能最全面.几乎涵盖任何模块无所不用无所不能的组件,掌握了它的灵巧使用,你就几乎掌握了大半个UGUI! 一.Button组件: Interactabl ...

  3. C# 连接 access2010数据库

    //定义一个新的OleDb连接 System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(); // ...

  4. VHDL之concurrent之operators

    Using operators Operators can be used to implement any combinational circuit. However, as will becom ...

  5. Python语言之常用函数

    1.input(),raw_input() input() = eval( raw_input() ) 其中raw_input()将所有的输入当做字符串处理. eval(str [,globals [ ...

  6. IronPython中共享的C#基类如何向下转型

    在项目中,我们使用IronPython来定义工作流脚本来以应对科研多变的需求.项目使用的主要语言仍然是C#,使用C#封装了各种基础服务与基础设施.Python脚本只使用C#提供的服务,或者说只定义了逻 ...

  7. 11.02 跳过表中n行

    select x.enamefrom (select a.ename,(select count(*)from emp bwhere b.ename <=a.ename) as rnfrom e ...

  8. (转)C#开发微信门户及应用(6)--微信门户菜单的管理操作

    http://www.cnblogs.com/wuhuacong/p/3701961.html 前面几篇继续了我自己对于C#开发微信门户及应用的技术探索和相关的经验总结,继续探索微信API并分享相关的 ...

  9. Higher-Order Functions and Lambdas

    https://kotlinlang.org/docs/reference/lambdas.html

  10. C# 截取字符串基本

    #region --构建字符串处理 string str1 = "123AAA456AAAA789AAAAAAA1011"; string str2 = "1234567 ...