Snowflake Snow Snowflakes(哈希表的应用)
Time Limit: 4000MS | Memory Limit: 65536K | |
Total Submissions: 27312 | Accepted: 7213 |
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<stdio.h>
#include<string.h>
#include<stdlib.h>
#define max 100010
struct vode
{
int f[];
struct vode *next;
};
struct vode *hash[];
int n,flag=;
void add(int f[],int sum)
{
sum=sum%max;
int i,j;
struct vode *p;
p=hash[sum];
while(p)
{
for(i=;i<=;i++)
if(f[i]==p->f[])
{
for(j=;j<=;j++)
if(f[(i+j)%]!=p->f[j])break;
if(j==)
{
flag=;
return ;
}
for(j=;j<=;j++)
if(f[((i-j)%+)%]!=p->f[j])break;
if(j==)
{
flag=;
return ;
}
}
p=p->next;
}
p=(struct vode *)malloc(sizeof(struct vode));
for(i=;i<=;i++)
p->f[i]=f[i];
p->next=hash[sum];
hash[sum]=p;
}
int main()
{
memset(hash,NULL,sizeof(hash));
scanf("%d",&n);
while(n--)
{
int i,f[],sum=;
for(i=;i<=;i++)
{
scanf("%d",&f[i]);
sum+=f[i];
}
if(flag)continue;
else add(f,sum);
}
if(flag)printf("Twin snowflakes found.");
else printf("No two snowflakes are alike.");
printf("\n");
return ;
}
Snowflake Snow Snowflakes(哈希表的应用)的更多相关文章
- poj3349 Snowflake Snow Snowflakes —— 哈希表
题目链接:http://poj.org/problem?id=3349 题意:雪花有6个瓣,有n个雪花,输入每个雪花的瓣长,判断是否有一模一样的雪花(通过旋转或翻转最终一样,即瓣长对应相等).如果前面 ...
- POJ3349 Snowflake Snow Snowflakes(哈希)
题目链接. 分析: 哈希竟然能这么用.检查两片雪花是否相同不难,但如果是直接暴力,定会超时.所以要求哈希值相同时再检查. AC代码: #include <iostream> #includ ...
- POJ 3349 Snowflake Snow Snowflakes(简单哈希)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 39324 Accep ...
- poj 3349:Snowflake Snow Snowflakes(哈希查找,求和取余法+拉链法)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 30529 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
相应POJ题目:点击打开链接 Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions ...
- 哈希-Snowflake Snow Snowflakes 分类: POJ 哈希 2015-08-06 20:53 2人阅读 评论(0) 收藏
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 34762 Accepted: ...
- POJ 3349:Snowflake Snow Snowflakes 六片雪花找相同的 哈希
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 35642 Accep ...
- [poj3349]Snowflake Snow Snowflakes(hash)
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 37615 Accepted: ...
随机推荐
- ThinkPHP函数详解:F方法(快速缓存方法)
在Think中S方法的用法,F方法其实是S方法的一个子集功能, 仅用于简直数据缓存,并且只能支持文件形式,不支持缓存有效期,因为采用 的是PHP返回方式,所以其效率较S方法较高,因此我们也称之为快速缓 ...
- idea 排除编译文件,恢复编译
- Discovering versions from the identity service failed when creating the password plugin.
If you are behind the proxy, then you have to set no_proxy environmental variable for your localhost ...
- Python之调用WebService:suds
suds官方: https://fedorahosted.org/suds/wiki/Documentation 互联网公开WSDL: http://www.webxml.com.cn/zh_cn/w ...
- CEF3开发者系列之进程间消息传递
在使用CEF3作为框架开发过程中,实现WebSockets.XMLHttpRequest.JS与本地客户端交互等功能时,需要在渲染(Render)进程和浏览(Browser)进程中传递消息.CEF3在 ...
- java压缩
/* @description:压缩文件操作 * @param filePath 要压缩的文件路径 * @param descDir 压缩文件保存的路径 d:\\aaa.zip */ public s ...
- 【linux】linux下运行java程序
参考了http://www.cnblogs.com/howard-queen/archive/2012/01/30/2331795.html 第一步:用vim先写一个java程序 first.jav ...
- 【linux】进程不要开太多,否则系统会卡死!
今天在跑一个任务,大概像下面这样 python task.py -s input/ input文件夹下有两百多个文件,比如1.txt, 2.txt等等,task.py会顺序读取并做操作. 我想,这不是 ...
- URAL 2019 Pair: normal and paranormal (贪心) -GDUT联合第七场
比赛题目链接 题意:有n个人每人拿着一把枪想要杀死n个怪兽,大写字母代表人,小写字母代表怪兽.A只能杀死a,B只能杀死b,如题目中的图所示,枪的弹道不能交叉.人和怪兽的编号分别是1到n,问是否存在能全 ...
- js生成验证码并验证
前台代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.as ...