Same Snowflake time limit: +Ms | Memory Limit:65535KB Difficulty:4
-
-
Descriptive narrative
- 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 the input would contain a single interger T (0<T<10), the number of the the test cases.
The first line of every test case would contain a single integer n, 0 < n≤100000, and the number of snowflakes 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
-
-
For each test case,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.
-
-
Example input
-
-
121 2 3 4 5 64 3 2 1 6 5
-
-
Example output
-
-
Twin snowflakes found.
-
-
Source
-
-
POJ
-
-
Uploaded by
-
-
Zhang Yunzun
Test instructions: Given a sequence of 6 groups of numbers, the inference is whether the two groups are equal, and the equivalence is based on the two sets of positive-order matching or reverse matching. key: Each snowflake is hashed with each set of keys and is then matched from the same snowflake.
#include <stdio.h> #include <string.h> #include <vector> #define MAXN 100001#define MOD 100001int N; struct Node {int a[6];} snow[maxn];std::vector<int> f[mod];void getData () {int I, J, Sum;memset (f, 0, sizeof (f)); SCA NF ("%d", &n); for (i = 0; i < n; ++i) {for (j = sum = 0; j < 6; ++j) {scanf ("%d", &snow[i].a[j]); sum + = Snow[i] . A[j];} F[sum% Mod].push_back (i);}} BOOL Judge (int x, int y) {int i, J, count;for (i = 0; i < 6; ++i) {if (snow[x].a[i] = = Snow[y].a[0]) {for (count = j = 0; J < 6; ++J) if (snow[x].a[(i+j)%6] = = Snow[y].a[j]) ++count;if (count = = 6) return True;for (count = j = 0; j < 6; ++j) if (snow[x].a [((I-J)%6+6)%6] = = Snow[y].a[j]) ++count;if (count = = 6) return true;}} return false;} BOOL Test (int k, int m) {int I, j;for (i = 0; i < m; ++i) for (j = i + 1; j < m; ++j) if (Judge (F[k][i], f[k][j]) return True;return false;} void Solve () {int I, j, k, ok = 0;for (i = 0; i < MOD; ++i) if (!f[i].empty () && test (I, F[i].size ())) {OK = 1; br Eak;} Printf (ok?) "Twin Snowflakes found.\n": "No, Snowflakes is alike.\n");} int main () {//Freopen ("Stdin.txt", "R", stdin), int t;scanf ("%d", &t), while (t--) {getData (); Solve ();} return 0;}
and then tried the following list: Results tle
#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXN 100001int n;struct Node {int a[6 ]; Node *next;}; struct Node2 {int sum; Node2 *nextnode2; Node *next;} Root;void Insertnode (Node2 *n2p, node tmp) {node *p = (node *) malloc (sizeof (node)); *p = tmp; p->next = n2p->next;n2 P->next = P;} void InsertNode2 (int sum, Node tmp) {Node2 *p = root.nextnode2, *q = &root;while (True) {if (!p | | p->sum > SUM) { Node2 *temp = (Node2 *) malloc (sizeof (NODE2)); temp->sum = sum; Temp->nextnode2 = P;temp->next = NULL; Q->nextnode2 = Temp;insertnode (temp, TMP); return;} else if (p->sum = = sum) {Insertnode (P, TMP); return;} Q = p; p = P->nextnode2;}} void Destorynode (node *p) {node *q;while (p) {q = p; p = p->next;free (q);}} void DestoryNode2 (Node2 *p) {Node2 *q;while (p) {Destorynode (p->next); q = p; p = p->nextnode2;free (q);}} void GetData () {int i, j, sum; Node Tmp;destorynode2 (root.nextnode2); root.nextnode2 = Null;root.next = Null;root.sum =-1;SCANF ("%d", &n); for (i = 0; i < n; ++i) {for (j = sum = 0; j < 6; ++j) {scanf ("%d", &tmp.a[j]); sum + = tmp.a[ j];} InsertNode2 (SUM, TMP);}} BOOL Judgearr (int a[], int b[]) {int I, J, cnt;for (i = 0; i < 6; ++i) {if (a[i] = = B[0]) {for (j = cnt = 0; j < 6; ++j if (a[(i+j)%6] = = B[j]) ++cnt;if (cnt = = 6) return true;for (j = cnt = 0; j < 6; ++j) if (a[(i-j+6)%6] = = B[j]) ++cnt;if (CN t = = 6) return true;}} return false;} BOOL Judgelist (node *PN) {node *p1, *p2;for (p1 = pn; p1; p1 = P1->next) {for (P2 = p1->next; P2; p2 = p2->next) if ( Judgearr (P1->a, P2->a)) return true; return false;} void Solve () {Node *np;for (Node2 *n2p = Root.nextnode2; n2p; n2p = N2p->nextnode2) {if (Judgelist (N2p->next)) {printf ("Twin snowflakes found.\n"); return;}} printf ("No. Snowflakes is alike.\n");} int main () {//Freopen ("Stdin.txt", "R", stdin), int t;scanf ("%d", &t), while (t--) {getData (); Solve ();} return 0;}
NYOJ130 the same snowflake "Hash"