poj3349 (hash + chain address method)

Source: Internet
Author: User

Give the 6 sides of the N hexagon, asking if there are exactly the same two hexagons, exactly the same length and position as the edges. The order of the edges is counterclockwise or clockwise.

Give each 6-edge a hash value by the square and modulo of the 6-edge length

#include <cstdio>#include<algorithm>#include<cstring>using namespacestd;Const intMAXN =1e6;Const intMoD =999983; a typedef of large primes within//100wLong LongLL;intN;Chars[100010][Ten];intHASH[MAXN],NEXT[MAXN];BOOLJudgeintAintb) {    inti,j,k;  for(i =0; I <6; ++i)//The starting position of the string { for(j = I,k =0; K <6; ++k,j = (j+1)%6)//Clockwiseif(S[a][k]! = S[b][j]) Break; if(k = =6)return true;  for(j = I,k =0; K <6; ++k, j = (j+5)%6)//counter-clockwiseif(S[a][k]! = S[b][j]) Break; if(k = =6)return true; }    return false;}intMain () {//freopen ("in", "R", stdin);scanf"%d",&N); BOOLFlag =false;  for(inti =1; I <= N; ++i) {intx =0, U;  for(intj =0; J <6; ++j) {scanf ("%d",&S[i][j]); X= (int) ((x+ (LL) s[i][j]* (LL) s[i][j])%mod);//Prevent overflow} u=Hash[x];//hash "" contains the line number of a line corresponding to the hash value. while(u) {if(Judge (I,u)) {flag =true; Break;} Just u!. =0, indicating that the hash value has occurred before, you may appear the same hexagon, judging the U=next[u];//go down the "linked list"if(flag) Break; Next[i]=hash[x];//similar to the insertion method of the linked list, the hash value of the same together, convenient for later use next can be traversed to all the same side of the hash hash[x]=i;//Update table header}if(flag) printf ("Twin Snowflakes found.\n"); Elseprintf"No. Snowflakes is alike.\n");}

poj3349 (hash + chain address method)

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.