Snowflake Snow Snowflakes
来源:互联网 发布:淘宝网商城清仓特价 编辑:程序博客网 时间:2024/06/05 23:48
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<stdlib.h>#include<math.h>#include<iostream>using namespace std;#define NN 15000#define NL 100#define L 6typedef struct{ int a[L];}item;item snow[NN][NL];int m[NN];int hash(item SNOW){ int i; int key=0; for(i=0;i<6;i++) key+=SNOW.a[i]; key%=14997; return key;}int cmp(item x,item y){ int st, i, j; for (st = 0; st < 6; st++){// 右移 for (i = st, j = 0; j < 6; j++, i = (i + 1) % 6){ if(x.a[i] != y.a[j]) break; } if(j == 6) return 1; } for (st = 0; st < 6; st++){// 左移 for (i = st, j = 0; j < 6; j++, i = (i + 5) % 6){ if(x.a[i] != y.a[j]) break; } if(j == 6) return 1; } return 0;}int main(){ int i,j,pos,n; item SNOW; scanf("%d",&n); memset(m,0,sizeof(m)); for(i=1;i<=n;i++) { for(j=0;j<6;j++) scanf("%d",&SNOW.a[j]); pos=hash(SNOW); for(j=0;j<m[pos];j++) { if(cmp(SNOW,snow[pos][j])) { puts("Twin snowflakes found."); return 0; } } snow[pos][m[pos]]=SNOW; m[pos]++; } puts("No two snowflakes are alike."); return 0;}
- poj3349 Snowflake Snow Snowflakes
- POJ3349 Snowflake Snow Snowflakes
- poj3349 Snowflake Snow Snowflakes
- Snowflake Snow Snowflakes poj3349
- poj3349 Snowflake Snow Snowflakes
- POJ3349--Snowflake Snow Snowflakes
- poj3349 Snowflake Snow Snowflakes
- POJ3349-Snowflake Snow Snowflakes
- 哈希-Snowflake Snow Snowflakes
- POJ3349---Snowflake Snow Snowflakes
- Snowflake Snow Snowflakes
- poj3349 Snowflake Snow Snowflakes
- Snowflake Snow Snowflakes----查找
- Snowflake Snow Snowflakes(哈希表)
- Snowflake Snow Snowflakes POJ
- Snowflake Snow Snowflakes
- Snowflake Snow Snowflakes
- Snowflake Snow Snowflakes POJ
- Linux加载库目录顺序
- 将十进制数转换为十六进制数
- 用python创建桌面应用(一)
- 小密圈产品事故@2017 No.2 --- 条件竞争提现
- 遍历List集合的三种方法
- Snowflake Snow Snowflakes
- 算法简介
- windows平台下删除注册表后应用程序无法使用的情况
- 欢迎使用CSDN-markdown编辑器
- R语言做文本挖掘 Part2分词处理
- 工具类-JSON串自动加前缀
- strcpy 和strlen函数的模拟实现
- ZOJ 3962 Seven Segment Display(数位dp)
- postman的使用