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: ...
随机推荐
- Panabit安装配置笔记
最近研究了linux下基于FREEBSD的开源流控软件Panabit,感觉功能还不错,单位公司如果经费不足的朋友需要做内网流控可以使用这款软件,最新免费版ISO镜像仅支持网桥模式和旁路模式,256个并 ...
- Shape + Selector: Make a Shape as one item of the Selector
Generally, I use a selector to select pictures or colors to render the normal and the pressed backgr ...
- echarts
ECharts,缩写来自Enterprise Charts,商业级数据图表,一个纯Javascript的图表库,可以流畅的运行在PC和移动设备上,兼容当前绝大部分浏览器(IE6/7/8/9/10/11 ...
- good luck
ACM大法好,明天求轻虐,水一波~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- mac 下搭建php 编程环境全过程
1,打开终端, 设置root密码sudo passwd root输入密码 2, 安装 apachemac 自带apache 启动apachectl start重新启动apachectl restart ...
- ext 对齐
layout : { type : 'hbox', pack : 'end' } buttonAlign:'center', //按钮居中 pack : String Controls how t ...
- phpstorm+Xdebug断点调试PHP
运行环境: PHPSTORM版本 : 8.0.1 PHP版本 : 5.6.2 xdebug版本:php_xdebug-2.2.5-5.6-vc11-x86_64.dll ps : php版本和xdeb ...
- 【leetcode】Gas Station
Gas Station There are N gas stations along a circular route, where the amount of gas at station i is ...
- C++实现双缓冲
首先声明下,这篇资料也是整理别人的资料的基础上,总结来的. 在图形图像处理过程中,双缓冲技术是一种比较常见的技术.窗体在响应WM_PAINT消息时,需要对图像进行绘制处理.如果图像绘制次数过多,重绘过 ...
- Light OJ 1032
数位dp,许多数位dp需要统计某种模式(子串)出现的数量,这种题通常需要在递归参数中加入高位已经出现过的模式的数量. #include <cstdio> #include <cstr ...