Snowflake Snow Snowflakes

Source: Internet
Author: User

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, and the number of snowflakes to Follow. This is being followed byn 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. 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.


The problem: Although the topic is not difficult, but still difficult. You can use map to map the clockwise and counterclockwise 12 of each snowflake to the same key that differs from other snowflakes, so that if you find the health value of the snowflake, you know it, but the map is inefficient. Timeout. So you can only use a hash, and divide all 6 corners by a large number (generally looking for the largest possible primes). But if the data pit Dad can not live ... If all is the same, it is not the N2, withered. Fortunately the data is withered ....


#include <iostream> #include <cstdio> #include <cstring> #include <map>using namespace std; struct Hash{int index; Hash* Next; Hash () {index = 0;next = NULL;}}; Map<int,int> Mp;bool Flag[11000005];int s[100005][10]; Hash hash[1100005];bool ok1 (int x,int key) {for (int i = 0;i < 6;i++) {int J;int y;for (j = 0,y = I;j < 6;j++) {if (s[x] [j]! = S[key][y]) {break;} y = (++y)% 6;} if (j = = 6) {return true;} for (j = 0,y = I;j < 6;j++) {if (s[x][j]! = S[key][y]) {break;} y = (--y + 6)% 6;} if (j = = 6) {return true;}} return false;} bool OK (int x,int key) {hash* p = hash[key].next;while (P! = NULL) {if (Ok1 (X,p->index)) {return true;} p = p->next;} return false;} int main () {int n;while (scanf ("%d", &n)! = EOF) {//mp.clear (); memset (flag,false,sizeof (flag)); bool F = false;int k = 1; for (int i = 0;i < n;i++) {int t = 0;for (int j = 0;j < 6;j++) {scanf ("%d", &s[i][j]); t + = s[i][j];}    int x = t% 958426;if (Flag[x]) {if (ok (i,x)) {printf ("Twin snowflakes found.\n"); F = true; Continue}hash* p = new Hash ();p->index = I;p->next = Hash[x].next;hash[x].next = P;} Else{//mp[t] = k++; hash* p = new Hash ();p->index = I;p->next = Hash[x].next;hash[x].next = P;flag[x] = true;}} if (!f) {printf ("No. Snowflakes is alike.\n");}} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Snowflake Snow Snowflakes

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.