poj 3349(hash)
2012-10-26 19:37
309 查看
第一次用vector,,感觉蛮方便的。
这个题需要判断同构,数据一样的枝条应该是不一定是相同的,但是数据貌似很水。比如
2
3 1 2 4 5 6
3 2 1 4 5 6
View Code
这个题需要判断同构,数据一样的枝条应该是不一定是相同的,但是数据貌似很水。比如
2
3 1 2 4 5 6
3 2 1 4 5 6
View Code
#include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <algorithm> using namespace std; #define MAXN 100010 #define HASH 100007 vector<int> hash[HASH];//hash表,表中存储的是snow数组的下标 int snow[MAXN][6]; int n; bool is_same(int a,int b)//同构 { for(int i=0;i<6;i++) { if(snow[a][0]==snow[b][i%6] && snow[a][1]==snow[b][(i+1)%6] && snow[a][2]==snow[b][(i+2)%6] && snow[a][3]==snow[b][(i+3)%6] && snow[a][4]==snow[b][(i+4)%6] && snow[a][5]==snow[b][(i+5)%6]) return true; if(snow[a][5]==snow[b][i%6] && snow[a][4]==snow[b][(i+1)%6] && snow[a][3]==snow[b][(i+2)%6] && snow[a][2]==snow[b][(i+3)%6] && snow[a][1]==snow[b][(i+4)%6] && snow[a][0]==snow[b][(i+5)%6]) return true; } return false; } int main() { while(~scanf("%d",&n)) { for(int i=0;i<n;i++) scanf("%d%d%d%d%d%d",&snow[i][0],&snow[i][1],&snow[i][2],&snow[i][3],&snow[i][4],&snow[i][5]); int sum,key,tag=0; for(int i=0;i<n&& !tag;i++) { sum=0; for(int j=0;j<6;j++) sum+=snow[i][j]; key=sum%HASH; for(int j=0;j<hash[key].size();j++) { if(is_same(i,hash[key][j])) { puts("Twin snowflakes found."); tag=1; break; } } hash[key].push_back(i); } if(!tag) puts("No two snowflakes are alike."); } return 0; }
相关文章推荐
- POJ-3349-Snowflake Snow Snowflakes-hash
- poj 3349_Snowflake Snow Snowflakes_hash
- 17 - 01 - 04 POJ 3349 (hash)
- POJ 3349 Snowflake Snow Snowflakes(hash)
- poj 3349 简单hash
- POJ3349【手写Hash】
- poj 3349(hash)
- hash应用以及vector的使用简介:POJ 3349 Snowflake Snow Snowflakes
- POJ-3349-Snowflake Snow Snowflakes - hash
- poj 3349 Snowflake Snow Snowflakes (hash)
- POJ 3349 Snowflake Snow Snowflakes(hash哈希表)
- POJ 3349 Snowflake Snow Snowflakes (hash)
- POJ 3349 Snowflake Snow Snowflakes hash
- poj 3349 Snowflake Snow Snowflakes (简单题 hash)
- poj 3349 hash的运用
- ACM: poj 3349 (学习hash多种方法.…
- POJ 3349 SNOWFLAKE SNOW SNOWFLAKES(HASH)
- Snowflake Snow Snowflakes POJ - 3349 hash(爆搜剪枝)
- POJ 3349 简单hash
- POJ3349 HASH