http://poj.org/problem?id=3349
Snowflake Snow Snowflakes
Time Limit: 4000MS |
|
Memory Limit: 65536K |
Total Submissions: 37609 |
|
Accepted: 9878 |
Description
You may have heard and snowflakes are alike. Your task is to write a program to determine whether the is really true. Your program would read information about a collection of the snowflakes, and search for a pair, the May is identical. Each snowflake have six arms. For each snowflake, your program is provided with a measurement of the length of each of the six arms. Any pair of snowflakes which has the same lengths of corresponding arms should be flagged by your program as possibly IDE Ntical.
Input
The first line of input would contain a single integer n, 0 < n ≤100000, the number of SN Owflakes to follow. This is being followed by n lines and each describing a snowflake. Each snowflake would be described by a line containing six integers (each integer was at least 0 and less than 10000000), th e lengths of the arms of the snow Ake. The lengths of the arms would be given on order around the snowflake (either clockwise or counterclockwise), but they may b Egin with any of the six arms. For example, the same snowflake could is described as 1 2 3 4 5 6 or 4 3 2 1 6 5.
Output
If all of the snowflakes is distinct, your program should print the message: No, the snowflakes is 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.
1#include <cstdio>2#include <algorithm>3#include <cstring>4#include <iostream>5 using namespacestd;6 #defineMOD 149977 structnode8 {9 intlen[6];Ten}snow,f[15000][ -]; One inthash[15000]; A - /* - First Hash the determine if two snowflakes are the same: - are clockwise and counterclockwise, as long as the condition is met and can be considered the same. - The first mod took 999983, the results of the MLE, and later looked at others to take the 14997 - */ + BOOLCheck (node A,node b) - { + inti,j,k; A BOOLFlag; at //Clockwise rotation judgment - for(i=0;i<6; i++){ -flag=true; - for(j=i,k=0;k<6; K++,j= (j+1)%6){ - if(a.len[j]!=B.len[k]) { -flag=false; Break; in } - } to if(flag)return 1; + } - //counter clockwise rotation judgment the for(i=0;i<6; i++){ *flag=true; $ for(j=i,k=0;k<6; K++,j= (j+5)%6){Panax Notoginseng if(a.len[j]!=B.len[k]) { -flag=false; Break; the } + } A if(flag)return 1; the } + return 0; - } $ $ intMain () - { - intN; the intNow ; -scanf"%d",&n);Wuyi //There is only one set of examples that are not initialized. the BOOLflag=false; - for(intI=0; i<n;i++){ Wunow=0; - for(intj=0;j<6; j + +){ Aboutscanf"%d",&snow.len[j]); $now+=snow.len[j]%MOD; - } - if(flag)Continue; -now%=MOD; A if(hash[now]>0){ + for(intj=1; j<=hash[now];j++){ the if(check (Snow,f[now][j])) { -flag=true; Break; $ } the } the } thehash[now]++; thef[now][hash[now]]=Snow; - } in if(flag) printf ("Twin Snowflakes found.\n"); the Elseprintf"No. Snowflakes is alike.\n"); the return 0; About}
2016-06-04
POJ 3349:snowflake Snow Snowflakes (number of hashes)