poj3349Snowflake Snow Snowflakes(哈希表)
来源:互联网 发布:数据新闻啥意思 编辑:程序博客网 时间:2024/06/07 19:37
Snowflake Snow Snowflakes
Time Limit: 4000MS Memory Limit: 65536K
Total Submissions: 42252 Accepted: 11099
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.
统计每个雪花边的和,作为哈希的地址标记,这样能快速查找
用vector对数据进行处理,将sum相同的进行push_back,然后再对sum.size()里面的数据进行查找,出现相同的就break
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <queue>#include <cmath>using namespace std;#define N 100010#define MOD 19999int n;int snow[N][6];vector<int>vec[20000];int isok(int s1,int s2){ for(int i=0;i<6;i++){ int flag=1; for(int j=0,k=i;j<6;j++,k=(k+1)%6){ if(snow[s1][j]!=snow[s2][k]){ flag=0; break; } } if(flag) return 1; } for(int i=0;i<6;i++){ int flag=1; for(int j=5,k=i;j>=0;j--,k=(k+1)%6){ if(snow[s1][j]!=snow[s2][k]){ flag=0; break; } } if(flag) return 1; } return 0;}int main(){ scanf("%d",&n); int flag=0; for(int i=0;i<n;i++) { int sum=0; for(int j=0;j<6;j++) { scanf("%d",&snow[i][j]); sum+=snow[i][j]; } if(flag) continue; sum=sum%MOD; for(int j=0;j<vec[sum].size();j++) { if(isok(vec[sum][j],i)) { flag=1; break; } } vec[sum].push_back(i); } if(flag) cout<<"Twin snowflakes found."<<endl; else cout<<"No two snowflakes are alike."<<endl; return 0;}
- poj3349Snowflake Snow Snowflakes(哈希表)
- Snowflake Snow Snowflakes(哈希表)
- POJ3349--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(hash哈希表)
- poj3349 Snowflake Snow Snowflakes —— 哈希表
- POJ 3349 Snowflake Snow Snowflakes (哈希表)
- POJ 3349 Snowflake Snow Snowflakes (哈希表)
- 【poj3349】Snowflake Snow Snowflakes(哈希表)
- poj Snowflakes snow snowflakes 哈希
- poj3349 Snowflake Snow Snowflakes
- POJ3349 Snowflake Snow Snowflakes
- poj3349 Snowflake Snow Snowflakes
- Snowflake Snow Snowflakes poj3349
- poj3349 Snowflake Snow Snowflakes
- day04数组 知识点和核心代码以及作业
- JavaEE应用的分层简介
- js全选
- POJ 1182 食物链(并查集)
- Section 2.1 frac1
- poj3349Snowflake Snow Snowflakes(哈希表)
- 剑指offer面试题-判断链表是否带环并求环的入口点和环的长度
- 音频
- LeetCode#21 Merge Two Sorted Lists
- zabbix 的安装
- scikit-learn对天气数据进行回归分析
- mapbox for unity 再现真实地图
- [USACO1.1]Broken Necklace C++(错误1)
- SSL certification verify