Poj 3349 -- snowflake snow snowflakes

Source: Internet
Author: User
Snowflake snow snowflakes
Time limit:4000 Ms   Memory limit:65536 K
Total submissions:30652   Accepted:8076

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 shocould be flagged by your program as possibly identical.

Input

The first line of input will contain a single integerN, 0 <N≤ 100000, the number of snowflakes to follow. This will be followedNLines, 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 cocould 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 shocould print the message:
No two snowflakes are alike.
If there is a pair of possibly identical snow akes, your program shocould print the message:
Twin snowflakes found.

Sample Input

21 2 3 4 5 64 3 2 1 6 5

Sample output

Twin snowflakes found.

Train of Thought: use hash to hash snow into a small range of values, and then search for this value. I used the zipper method to implement hash.

1/* ============================================== ====================================== 2 * Author: kevin 3 * filename: snowflakesnowsnowflackes. CPP 4 * creat time: 5 * description: 6 ================================================ ===================================== */7 # include <iostream> 8 # include <algorithm> 9 # include <cstdio> 10 # include <cstring> 11 # include <queue> 12 # include <cmath> 13 # define CLR (a, B) memset (a, B, sizeof (A) 14 # define M 502115 using namespace STD; 16 struct snow {17 int s [6]; 18} snow; 19 vector <snow> VEC [M + 5]; 20 bool judge (int adr, int K, snow SnO) 21 {22 int I, J; 23 For (I = 0; I <6; I ++) {24 if (Sno. s [0] = VEC [ADR] [K]. s [I]) {25 for (j = 1; j <6; j ++) {26 if (Sno. s [J]! = VEC [ADR] [K]. s [(j + I) % 6]) 27 break; 28} 29 If (j = 6) return true; 30 for (j = 1; j <6; j ++) {31 if (Sno. s [6-j]! = VEC [ADR] [K]. s [(I + J) % 6]) 32 break; 33} 34 if (j = 6) return true; 35} 36} 37 return false; 38} 39 int searchhash (INT key, snow SnO) 40 {41 int ADR = Key % m; 42 int Len = VEC [ADR]. size (); 43 for (INT I = 0; I <Len; I ++) {44 If (Judge (ADR, I, SnO) {45 return 1; 46} 47} 48 VEC [ADR]. push_back (SNO); 49 return 0; 50} 51 int main (INT argc, char * argv []) 52 {53 int N, flag = 0; 54 scanf ("% d", & N); 55 while (n --) {56 int sum = 0; 57 scanf ("% d", & Snow. s [0]); 58 sum = snow. s [0]; 59 for (INT I = 1; I <6; I ++) {60 scanf ("% d", & Snow. s [I]); 61 sum = sum ^ snow. s [I]; 62} 63 If (! Flag) {64 if (searchhash (sum, snow) {// If 65 flag = 1; 66} 67} 68} 69 If (! Flag) printf ("no two snowflakes are alike. \ n"); 70 else {71 printf ("twin snowflakes found. \ n"); 72} 73 return 0; 74}
View code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.