Time Limit: 2500 MS Memory Limit: 32768 K

## Description

Chen Yueyue's favorite season is winter. Instead of looking at the snowflakes floating outside the window, Chen Yueyue happily ran out of the house to see the snow. But the confused Chen Yueyue didn't know whether he was dreaming or whether it really snowed. Suddenly she remembered a sentence that there are no two snowflakes in the real world. So your task is to compare all the snowflakes in the snow. If two identical snowflakes appear, it proves that Chen moon is in a dream.

Each snowflake is represented by six integers, ranging from (1 – 10000000), indicating the length of the six petals of the snowflake. The sequence of the six integers may be clockwise or counterclockwise, and may start from any petal. For example, for the same petal, the description method may be 1 2 3 4 5 6 or 4 3 2 1 6 5

## Input

The first line is an integer T, indicating that there are t groups of test data.

The first line of each group of test data is an integer n (0 < n < = 100000), representing the number of snowflakes.

Next, n lines, each with six integers, describe a snowflake.

## Output

If there are no identical snowflakes, output "no two snowflakes are like." otherwise, output "Twin snowflakes found."

## Sample Input

1

2

1 2 3 4 5 6

4 3 2 1 6 5

## Sample Output

Twin snowflakes found.

## Source

2016 national invitational competition for freshmen programming

## meaning of the title

N sequences are given. If the sequences obtained by reading the sequences clockwise or counterclockwise from any position are the same, the two sequences are exactly the same. Find out if there are two identical sequences in the given sequence.

## thinking

For each sequence, we can use its sequence and as a hash value to store the same hash value in a linear table. For a new sequence, we only need to query whether there are elements with the same hash value in the stored hash table.

Of course, for the same hash value, there may also be unequal sequences. At this time, we only need to use an alignment function to align all possible sequences.

When the sequence is inserted into the hash table, if the hash values are the same but the sequences are different, we need to store them in different locations under the same hash value. At this time, we need to create an array for each hash value to record the same hash value but different sequences.

Therefore, vector < int > is the data structure for storing this question and the storage method of hash table in this question.

The read in is very large, so you can consider using the read in hook.

The read in hook is twice as fast as scanf.

## AC code

877607 2300 Accepted G++ 355ms 7144k software - Chord 1985B 2019-04-03 21:30:03

#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; int a[maxn][6]; bool check(int o, int t) { for (int i = 0; i < 6; i++) if ((a[o][0] == a[t][i % 6] && a[o][1] == a[t][(i + 1) % 6] && a[o][2] == a[t][(i + 2) % 6] && a[o][3] == a[t][(i + 3) % 6] && a[o][4] == a[t][(i + 4) % 6] && a[o][5] == a[t][(i + 5) % 6]) || (a[o][0] == a[t][i % 6] && a[o][1] == a[t][(i + 5) % 6] && a[o][2] == a[t][(i + 4) % 6] && a[o][3] == a[t][(i + 3) % 6] && a[o][4] == a[t][(i + 2) % 6] && a[o][5] == a[t][(i + 1) % 6])) return true; return false; } template <class T> inline bool scan_d(T &ret) { char c; int sgn; if (c = getchar(), c == EOF) return 0; while (c != '-' && (c < '0' || c > '9')) c = getchar(); sgn = (c == '-') ? -1 : 1; ret = (c == '-') ? 0 : (c - '0'); while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0'); ret *= sgn; return 1; } int main(void) { std::ios::sync_with_stdio(false); int t; scan_d(t); while (t--) { int n; scan_d(n); for (int i = 0; i < n; i++) for (int j = 0; j < 6; j++) scan_d(a[i][j]); vector<int> Hash[maxn]; int flag = 0; for (int i = 0; i < n; i++) { int sum = 0; for (int j = 0; j < 6; j++) sum += a[i][j]; sum %= maxn; for (int j = 0; j < Hash[sum].size(); j++) { if (check(i, Hash[sum][j])) flag = 1; if (flag) break; } if (flag) break; Hash[sum].push_back(i); } if (flag) cout << "Twin snowflakes found." << endl; else cout << "No two snowflakes are alike." << endl; } return 0; }

Created on: April 5, 2019