POJ 3349 SNOWFLAKE SNOW SNOWFLAKES(HASH)
来源:互联网 发布:淘宝老酒拍卖会不会假 编辑:程序博客网 时间:2024/05/16 14:45
原文:http://blog.acmj1991.com/?p=626
题意:给你雪花六个花瓣的长度,找是否有相同的雪花。
注意相同不一定是题目input给定的位置相同每个数相等,如:
1 2 3 4 5 6
6 1 2 3 4 5
6 5 4 3 2 1
思路:对每个雪花长度总和进行hash
很久以前做过这个题目,但是没做出来。现在想想那时候真是太菜了,现在没以前那么菜了。真是不在太菜中成长,就在太菜中灭亡….
#include<stdio.h>#include<string.h> #define maxN 100010#define A 1000000int head[A+10],num;struct point{ int key[6],next;}po[maxN]; bool add(int a[]){ int sum=0; for(int i=0;i<6;i++)sum^=a[i]; int j,i,m,h=sum%A; m=head[h]; while(m!=-1) { for(i=0;i<6;i++) if(a[i]==po[m].key[0]){ for(j=1;j<6;j++) if(a[(i+j)%6]!=po[m].key[j])break; if(j==6)return true; for(j=1;j<6;j++) if(a[((i-j)%6+6)%6]!=po[m].key[j])break; if(j==6)return true; } m=po[m].next; } for(i=0;i<6;i++)po[num].key[i]=a[i]; po[num].next=head[h];head[h]=num++; return false;} int main(){ int n,a[7],flag=0; num=0; memset(po,0,sizeof(po)); memset(head,-1,sizeof(head)); scanf("%d",&n); while(n--) { for(int i=0;i<6;i++) scanf("%d",&a[i]); if(flag)continue; if(add(a))flag=1; } if(flag) printf("Twin snowflakes found.\n"); else printf("No two snowflakes are alike.\n"); }
- 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 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-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)
- 云计算之lotus及实例
- 函数指针数组的妙用
- 从尾到头输出链表
- 性能检测及调优tips
- hdu 1211 RSA 解密
- POJ 3349 SNOWFLAKE SNOW SNOWFLAKES(HASH)
- 函数指针数组
- POJ 3274 GOLD BALANCED LINEUP(HASH)
- 关于我对于自己今后编程的要求
- poj 1979 zoj 2165 Red and Black 深搜做法
- POJ 2181 JUMPING COWS(DP)
- matlab下安装libsvm遇到的问题
- win7 联想一键恢复工程师版7.0安装笔记
- Spring MVC 之 AbstractCommandController