POJ 3349 Snowflake Snow Snowflakes
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                POJ 3349 Snowflake Snow Snowflakes
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.                        
                                
                            
                            
                            /*
哈希第一題啊..! 謝謝 http://www.cnblogs.com/Dario67/archive/2011/04/09/2010724.html 的博主
這題投機取巧了,判斷是否相等 直接排序 比較相等 混過去了 實際題目意思不是這樣的 呵呵
*/
#include <stdio.h>
#include <stdlib.h>#define M 99991		//大素數(shù) 這是怎么來的我還不清楚
#define MAXN 100000
struct flake{int arm[6];struct flake *next;  //拉鏈法處理沖突void init(){next = NULL;}
}snow[MAXN];int hash(int a[]){return ((a[0] + a[2] + a[4]) & (a[1] + a[3] + a[5])) % M;	//discuss里復(fù)制的...
}
bool same(int a[], int b[]){	for(int i = 0; i < 6; ++i){if(a[i] != b[i])return false;}return true;
}
bool search(int idx, int arm[]){flake *p = &snow[idx];p = p -> next;while( p ){if( same(p -> arm, arm)){return true;}p = p -> next;}return false;
}
void insert(int idx, flake *newsnow){flake *p = &snow[idx];newsnow -> next = p -> next;p -> next = newsnow;
}int cmp(const void *a, const void *b){return *(int*)a - *(int*)b;
}
int main(){int n;bool find = false;flake *nsnow;for(int i = 0; i < MAXN; ++i)snow[i].init();scanf("%d",&n);for(int i = 0; i < n; ++i){nsnow = (flake*)malloc(sizeof(flake));for(int j = 0; j < 6; ++j){scanf("%d",&nsnow -> arm[j]);}qsort(nsnow -> arm, 6, sizeof(int), cmp);int idx = hash(nsnow -> arm);	//找到散列值//printf("%d\n",idx);if(!search(idx, nsnow -> arm)){	//沒插入過insert(idx, nsnow);} else {printf("Twin snowflakes found.\n");return 0;}}printf("No two snowflakes are alike.\n");return 0;
}
 
 
                        
                        
                        轉(zhuǎn)載于:https://www.cnblogs.com/lxf90/archive/2011/04/12/2013175.html
總結(jié)
以上是生活随笔為你收集整理的POJ 3349 Snowflake Snow Snowflakes的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: Direct2D (35) : 通过 D
 - 下一篇: asp.net中关于静态页面生成的代码实