Poj 3349 (hash weight)

Source: Internet
Author: User

Interesting question.

It is not difficult to think about it. Hash is used to judge the weight, but the question is how to sort each series according to the same rule at the beginning.

For example

2 1 2 1 2

1 1 2 2 1 2

How to convert to 1 1 2 2 1 2, that is, to the minimum Lexicographic Order, there is no way to only enumeration, 3000 + MS is dangerous.

 

Snowflake snow snowflakes
Time limit:4000 Ms   Memory limit:65536 K
Total submissions:26254   Accepted:6900

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.

Source

CCC 1, 2007

 

# Include <stdio. h> # Include < String . H> # Include <Iostream> Using   Namespace  STD;  # Define N 1010000 # Define Mod4 1000007 # Define INF 10000001Typedef _ int64 ll;  Struct  Node {  Int  Next;  Int G [ 6  ];} Edge [N];  Int  CNT, pre [N];  Int  Flag1;  Void Hash (LL key, Int K [ 6  ]) { For ( Int P = pre [Key]; P! =- 1 ; P = Edge [p]. Next ){  Int FF = 0  ;  For ( Int I = 0 ; I < 6 ; I ++ )  If (K [I]! =Edge [p]. g [I]) {FF = 1  ;  Break  ;}  If (FF = 0  ) {Flag1 = 1  ;  Return  ;}}  For ( Int I =0 ; I < 6 ; I ++ ) Edge [CNT]. g [I] = K [I]; edge [CNT]. Next = Pre [Key]; Pre [Key] = CNT ++ ;}  Int  Main (){  Int  N;  While (Scanf ( "  % D  " , & N )! =EOF ){  Int K [ 6 ], TK [ 6 ], MK [ 6  ]; CNT = 0  ; Memset (PRE, - 1 , Sizeof  (Pre); flag1 = 0  ;  For (Int I = 0 ; I <n; I ++ ){  For ( Int I = 0 ; I < 6 ; I ++ ) MK [I] = INF;  For ( Int J = 0 ; J < 6 ; J ++) {Scanf (  "  % D  " ,& K [J]);}  If (Flag1 = 1 ) Continue  ;  /* Int flag = 1; int T1 = s, T2 = s; For (Int J = 0; j <5; j ++) {T1 ++; if (T1> = 6) T1-= 6; T2 --; If (t2 <0) T2 + = 6; If (K [T1]> K [T2]) {flag =-1; // indicates reverse break;} If (K [T1] <K [T2]) {flag = 1; break ;}} for (Int J = 0; j <6; j ++) {TK [J] = K [s]; S + = flag; If (S> = 6) s-= 6; If (S <0) S + = 6 ;}  */              For ( Int J = 0 ; J <6 ; J ++ ){  For ( Int I1 = 0 ; I1 < 6 ; I1 ++ ) TK [I1] = K [(I1 + J) % 6  ];  Int F = 0  ;  For ( Int I1 =0 ; I1 < 6 ; I1 ++ ){  If (MK [I1] < TK [I1]) {  Break  ;}  If (MK [I1]> TK [I1]) {f = 1  ;  Break ;}}  If (F = 1  ){  For ( Int I1 = 0 ; I1 < 6 ; I1 ++ ) MK [I1] = TK [I1] ;}}  For ( Int J = 0 ; J < 6 ; J ++ ){  For ( Int I1 = 0 ; I1 < 6 ; I1 ++ ) TK [I1] = K (j-i1 + 6 ) % 6  ];  Int F = 0  ;  For ( Int I1 = 0 ; I1 < 6 ; I1 ++ ){  If (MK [I1] < TK [I1]) {  Break  ;}  If (MK [I1]> TK [I1]) {f = 1  ; Break  ;}}  If (F = 1  ){  For ( Int I1 = 0 ; I1 < 6 ; I1 ++ ) MK [I1] = TK [I1];} ll TMP = 0  ; For ( Int J = 0 ; J < 6 ; J ++ ) {TMP = (TMP * 100000007 + MK [J]) % MOD;} Hash (TMP, MK );}  If (Flag1 = 0 ) Printf ( "  No two snowflakes are alike. \ n  "  ); Else Printf ( "  Twin snowflakes found. \ n  "  );}  Return   0  ;} 

 

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.