相同的雪花

时间限制:1000 ms  |  内存限制:65535 KB
难度:4
 
描述
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.
 
输入
The first line of the input will contain a single interger T(0<T<10),the number of the test cases.
The first line of every test case 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.
输出
For each test case,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.
样例输入
1
2
1 2 3 4 5 6
4 3 2 1 6 5
样例输出
Twin snowflakes found.

注意hash表大小
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<iomanip>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<fstream>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 100001
#define INF 1000000009
#define eps 0.00000001
/*
寻找是否有两片相同的雪花
雪花的边可能从任意一边 开始!
Hash 雪花总边长
*/
typedef struct Hashnode
{
int a[];
struct Hashnode* next;
}*List;
typedef struct HashT
{
List* L;
}*HashTable;
int NextPrime(int n)
{
int i;
for (int tmp = n;; tmp++)
{
for (i = ; i*i <= tmp; i++)
{
if (tmp%i == )
break;
}
if (i*i > tmp)
return i;
}
}
HashTable Init(int n)
{
HashTable H = (HashTable)malloc(sizeof(HashT));
H->L = (List*)malloc(sizeof(List)*MAXN);
for (int i = ; i < MAXN; i++)
{
H->L[i] = (List)malloc(sizeof(Hashnode));
memset(H->L[i]->a, , sizeof(H->L[i]->a));
H->L[i]->next = NULL;
}
return H;
}
void Free(HashTable H)
{
for (int i = ; i < MAXN; i++)
free(H->L[i]);
free(H->L);
free(H);
}
int Hash(int sum, int h)
{
return sum%h;
}
List Find(int a[], int sum, HashTable H)
{
List p = H->L[Hash(sum, MAXN)];
List l = p->next;
int i;
while (l != NULL)
{
for (int j = ; j < ; j++)
{
if (l->a[j] == a[])
{
for (i = ; i < ; i++)
{
if (l->a[(j + i) % ] != a[i])
break;
}
if (i == ) return l;
for (i = ; i < ; i++)
{
if (l->a[(j - i + ) % ] != a[i])
break;
}
if (i == ) return l;
}
}
l = l->next;
}
return NULL;
}
bool Insert(int a[], int sum, HashTable H)
{
List L = H->L[Hash(sum, MAXN)];
List p = Find(a, sum, H);
if (p == NULL)
{
List tmp = (List)malloc(sizeof(Hashnode));
for (int i = ; i < ; i++)
tmp->a[i] = a[i];
tmp->next = L->next;
L->next = tmp;
return true;
}
return false;
}
int main()
{
int T, n, tmp[];
bool f;
scanf("%d", &T);
while (T--)
{
scanf("%d", &n);
f = false;
HashTable H = Init(n);
for (int i = ; i < n; i++)
{
int sum = ;
for (int j = ; j < ; j++)
{
scanf("%d", &tmp[j]);
sum += tmp[j];
}
if (!f && !Insert(tmp, sum, H))
f = true;
}
if (f)
printf("Twin snowflakes found.\n");
else
printf("No two snowflakes are alike.\n");
Free(H);
}
return ;
}

相同的雪花 Hash的更多相关文章

  1. nyoj-130-相同的雪花(hash)

    题目链接 /* Name:NYOJ-130-相同的雪花 Copyright: Author: Date: 2018/4/14 15:13:39 Description: 将雪花各个分支上的值加起来,h ...

  2. POJ 3349 HASH

    题目链接:http://poj.org/problem?id=3349 题意:你可能听说话世界上没有两片相同的雪花,我们定义一个雪花有6个瓣,如果存在有2个雪花相同[雪花是环形的,所以相同可以是旋转过 ...

  3. 0x14 hash

    被虐爆了 cry 我的hash是真的菜啊... poj3349 肝了一个上午心态崩了...一上午fail了42次我的天,一开始搞了个排序复杂度多了个log,而且是那种可能不同值相等的hash,把12种 ...

  4. POJ 3349 Snowflake Snow Snowflakes(哈希表)

    题意:判断有没有两朵相同的雪花.每朵雪花有六瓣,比较花瓣长度的方法看是否是一样的,如果对应的arms有相同的长度说明是一样的.给出n朵,只要有两朵是一样的就输出有Twin snowflakes fou ...

  5. 【hash表】收集雪花

    [哈希和哈希表]收集雪花 题目描述 不同的雪花往往有不同的形状.在北方的同学想将雪花收集起来,作为礼物送给在南方的同学们.一共有n个时刻,给出每个时刻下落雪花的形状,用不同的整数表示不同的形状.在收集 ...

  6. Acwing:137. 雪花雪花雪花(Hash表)

    有N片雪花,每片雪花由六个角组成,每个角都有长度. 第i片雪花六个角的长度从某个角开始顺时针依次记为ai,1,ai,2,…,ai,6ai,1,ai,2,…,ai,6. 因为雪花的形状是封闭的环形,所以 ...

  7. NYOJ130 同样的雪花 【Hash】

    同样的雪花 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描写叙述 You may have heard that no two snowflakes are alike. ...

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

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

  9. [poj3349]Snowflake Snow Snowflakes(hash)

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

随机推荐

  1. 如何在vue项目中引入阿里巴巴的iconfont图库

    1. 打开 http://www.iconfont.cn/ 2. 选择我们喜欢的图标,点击上面的小车,加入图标库,即右侧的购物车 3.点击购物车,点击下载代码 4.解压下载的文件夹,将文件夹复制到 a ...

  2. zabbix监控kafka消费

    一.Kafka监控的几个指标 1.lag:多少消息没有消费 lag=logsize-offset 2.logsize:Kafka存的消息总数 3.offset:已经消费的消息 Kafka管理工具 介绍 ...

  3. webpack的初步使用(01)

    webpack:1.安装:在项目文件下先npm init初始化,一路回车2.进入到建立的项目下:cd projectname3.安装webpack:npm install webpack --save ...

  4. 阿拉伯数字1与英语字母l造成的代码bug

    <img src="./images/demo3/1a.png" /> <img src="./images/demo3/la.png" /& ...

  5. 321 Create Maximum Number 拼接最大数

    已知长度分别为 m 和 n 的两个数组,其元素由 0-9 构成,直观地表示两个自然数各位上的数字.现在从这两个数组中选出 k (k <= m + n) 个数字拼接成一个新的数,要求从同一个数组中 ...

  6. shell script练习:利用日期进行文件的创建

    随日期变化:利用 date 进行文件的创建 想像一个状况,假设我的服务器内有数据库,数据库每天的数据都不太一样,因此当我备份时, 希望将每天的数据都备份成不同的档名,这样才能够让旧的数据也能够保存下来 ...

  7. 解决Sql中DIstinct与Order By共同使用的冲突问题

    1.需求场景: 需要把最新更新文章的前五名作者展示出来. 2.解决问题第一步: select top 5 creator from table order by updateDate desc 结果: ...

  8. Croppic插件使用介绍-asp.net

    具体的参数使用和基本使用方式请看:http://www.uedsc.com/croppic-api.html 需要说明的几点: 1.支持两种上传方式: (1)先将原图上传至服务器,然后再次将切图信息传 ...

  9. pptp服务故障

    pptp服务故障记录 原文地址:http://www.cnblogs.com/caoguo/p/4994512.html 1.pptp部署是遇到开了防火墙端口不能拨号,拨号是提示错误如下: 但是关闭防 ...

  10. listcontrol 加combobox实现

    头文件 #pragma once#include "D:\Work\山东项目\StandardizedDrawing\sdUtils\CSGrid.h"#include " ...