POJ 3349 ——Snowflake Snow Snowflakes 链地址法哈希
来源:互联网 发布:telnet 端口号 结果 编辑:程序博客网 时间:2024/06/04 01:34
Memory Limit: 65536KTotal Submissions: 32269
Accepted: 8497
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
21 2 3 4 5 64 3 2 1 6 5
Sample Output
Twin snowflakes found.
Source
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;struct node{ int data; node *next;}head[100010];int mp[100010][6];int main(){ int n,js; bool flag = false; memset(head,0,sizeof(head)); scanf("%d",&n); for(int i = 0;i < n;i++) { for(int j = 0;j < 6;j++) { scanf("%d",&mp[i][j]); } if(flag) continue; sort(mp[i],mp[i] + 6); int zh = mp[i][0] % 100000; node *p = (&head[zh])->next; node *q = &(head[zh]); while(p) { js = 0; for(int j = 0;j < 6;j++) { if(mp[p->data][j] == mp[i][j]) js++; else break; } if(js == 6) { flag = true; break; } q = p; p = p->next; } if(!p) { node *r = new node; r->data = i; r->next = NULL; q->next = r; } } if(flag) printf("Twin snowflakes found.\n"); else printf("No two snowflakes are alike.\n"); return 0;}
- POJ 3349 ——Snowflake Snow Snowflakes 链地址法哈希
- POJ 3349—— Snowflake Snow Snowflakes
- 哈希—— POJ 3349 Snowflake Snow Snowflakes
- POJ 3349 Snowflake Snow Snowflakes
- POJ 3349 Snowflake Snow Snowflakes
- poj 3349 Snowflake Snow Snowflakes
- POJ 3349 Snowflake Snow Snowflakes
- POJ 3349 Snowflake Snow Snowflakes
- poj-3349 Snowflake Snow Snowflakes
- POJ 3349 Snowflake Snow Snowflakes
- POJ 3349 Snowflake Snow Snowflakes
- POJ 3349 Snowflake Snow Snowflakes
- POJ 3349 Snowflake Snow Snowflakes
- POJ 3349 Snowflake Snow Snowflakes
- POJ 3349 Snowflake Snow Snowflakes
- poj 3349 Snowflake Snow Snowflakes
- POJ 3349 Snowflake Snow Snowflakes
- poj 3349 Snowflake Snow Snowflakes
- DefaultHttpClient 与 AndroidHttpClient 的区别
- 获取 屏幕大小和 dp 等屏幕参数
- LeetCode—Majority Element
- Oracle 没有查询数据,但是视图中有
- Leetcode -- N_Queens II
- POJ 3349 ——Snowflake Snow Snowflakes 链地址法哈希
- 使用Mysql对URL进行索引
- 微信营销十九招 ! 转载
- 如何从后台开启android蓝牙的可见性以及始终保持可见性
- adb 命令抓取log日志方法
- unity游戏之刀塔传奇山寨版:斥资千万推海外电视广告
- WebService——CXF方式创建WebService服务端
- OpenCV 随机森林使用方法
- el 和jstl