Poj3349 (snowflake snow snowflakes)

Source: Internet
Author: User

Address: snowflake snow snowflakes

 

Question:

Give you n snowflakes, each of which consists of six lengths. Let you determine whether two or more of the N's snowflakes are similar. The similarity rules are as follows: there are two snowflake A and B. B turns clockwise or counterclockwise at any position and the size order of A is the same as that of snow.

 

Solutions;

If the time complexity of the general method is O (n ^ 2), it will time out, so try to make n small, all use a simple hash. Store the remainder of the six numbers and N to a vector. Then we can look for a similar snowflake in the vector.

 

Code:

1 # include <algorithm> 2 # include <iostream> 3 # include <sstream> 4 # include <cstdlib> 5 # include <cstring> 6 # include <cstdio> 7 # include <string> 8 # include <bitset> 9 # include <vector> 10 # include <queue> 11 # include <stack> 12 # include <cmath> 13 # include <list> 14/ /# include <map> 15 # include <set> 16 using namespace STD; 17 /************************************** */18 # define ll long 19 # Define int64 _ int64 20 /******************************** * *****/21 const int INF = 0x7f7f7f7f; 22 const double EPS = 1e-8; 23 const double PIE = ACOs (-1.0); 24 const int d1x [] = {0,-, 1 }; 25 const int d1y [] = {-,}; 26 const int d2x [] = {0,-, 1}; 27 const int d2y [] =, -}; 28 const int FX [] = {-1,-1,-,}; 29 const int FY [] = {-, 1, -,-, 1}; 30/* vector <int> map [N]; Map [A]. P Ush_back (B); int Len = map [v]. size (); */31 /************************************ * **/32 void openfile () 33 {34 freopen ("data. in "," rb ", stdin); 35 freopen (" data. out "," WB ", stdout); 36} 37/************************** gorgeous split line, the above is the template section ***************/38 const int n = 999; 39 int N; 40 typedef struct 41 {42 int A [6]; 43 long sum; 44} node; 45 node; 46 vector <node> VC [N]; 47 int cmp2 (INT A1 [], int A2 []) 48 {49 int I, j; 50 int cnt1 = 0, cnt2 = 0; 51 for (I = 0; I <6; I ++) 52 {53 If (A1 [0] = a2 [I]) 54 {55 for (cnt1 = 0, j = 1; j <6; j ++) 56 {57 int v = I + J; 58 If (V> = 6) 59 V-= 6; 60 if (A1 [J] = a2 [v]) 61 cnt1 ++; 62} 63 If (cnt1 = 5) 64 return 1; 65 for (cnt2 = 0, j = 1; j <6; j ++) 66 {67 int v = I-j; 68 if (v <0) 69 V + = 6; 70 If (A1 [J] = a2 [v]) 71 cnt2 ++; 72} 73 If (cnt2 = 5) 74 return 1; 75} 76} 77 return 0; 78} 79 in T CMP1 () 80 {81 int I, j, k; 82 for (I = 0; I <n; I ++) 83 {84 For (j = 0; j <VC [I]. size (); j ++) 85 for (k = J + 1; k <VC [I]. size (); k ++) 86 {87 If (VC [I] [J]. sum = VC [I] [K]. sum & cmp2 (VC [I] [J]. a, VC [I] [K]. a) 88 return 1; 89} 90} 91 return 0; 92} 93 int main () 94 {95 while (scanf ("% d", & N )! = EOF) 96 {97 int I, j; 98 for (I = 0; I <n; I ++) 99{ 100 node. sum = 0; 101 For (j = 0; j <6; j ++) 102 {103 scanf ("% d", & node. A [J]); 104 node. sum + = node. A [J]; 105} 106 VC [node. sum % N]. push_back (node); 107} 108 If (CMP1 () 109 printf ("twin snowflakes found. \ n "); 110 else111 printf (" no two snowflakes are alike. \ n "); 112 for (I = 0; I <n; I ++) 113 VC [I]. clear (); 114} 115 return 0; 116} 117/* 118 2119 1 2 3 4 5 6120 2 3 4 5 6 7121 2122 1 2 3 3 2123 1 2 2 3124. */
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.