poj 3349 Snowflake Snow Snowflakes【HASH】/【最小表示】
来源:互联网 发布:IT界伍飞宇 编辑:程序博客网 时间:2024/06/05 01:02
发现最小表示+sort好像还快一点点
HASH
#include<iostream>#include<vector>#include<cstdio>using namespace std;const int maxn=9997;struct node{ int a[6],sum;};vector<node> v[maxn];bool cmp(node b,node c){ if(b.sum!=c.sum) return 0; for(int j,i=0;i<6;i++) if(b.a[0]==c.a[i]) { for(j=1;j<6;j++) if(b.a[j]!=c.a[(i+j)%6]) break; if(j==6) return 1; for(j=1;j<6;j++) if(b.a[6-j]!=c.a[(i+j)%6]) break; if(j==6) return 1; } return 0;}bool find(){ for(int i=0;i<maxn;i++) for(int j=0;j<v[i].size();j++) for(int k=j+1;k<v[i].size();k++) if(cmp(v[i][j],v[i][k])) return 1; return 0;}int read(int &d){ char ch; while(ch=getchar(),ch>57||ch<48); d=ch-48; while(ch=getchar(),ch<=57&&ch>=48) d=d*10+ch-48; return d;}int main(){ int t;node k; read(t); while(t--) { k.sum=0; for(int i=0;i<6;i++) k.sum+=read(k.a[i]); v[k.sum%maxn].push_back(k); } puts(find()?"Twin snowflakes found.":"No two snowflakes are alike."); return 0;}
最小表示
#include<cstdio>#include<algorithm>#include<vector>using namespace std;const int maxn=100000+10;struct node{ int s[6];}a[maxn];int read(int &d){ char ch; while(ch=getchar(),ch>57||ch<48); d=ch-48; while(ch=getchar(),ch<58&&ch>47) d=d*10+ch-48; return d;}int getmin(int a[],int len){ int p=0,q=1,k=0,cmp; while(p<len&&q<len&&k<len) { cmp=a[(p+k)%len]-a[(q+k)%len]; if(cmp==0){k++;continue;} if(cmp>0) p+=k+1; else q+=k+1; if(p==q) q++; k=0; } return min(p,q);}bool cmp(node a,node b){ for(int i=0;i<6;i++) if(a.s[i]!=b.s[i]) return a.s[i]<b.s[i]; return false;}int main(){ int t,m,n,b[6],c[6],cnt=0; read(t); while(t--) { for(int i=0;i<6;i++) { c[5-i]=read(b[i]); } m=getmin(b,6),n=getmin(c,6); bool flag; for(int i=0;i<6;i++) if(b[(i+m)%6]>c[(i+n)%6]){flag=1;break;} else if(b[(i+m)%6]<c[(i+n)%6]){flag=0;break;} if(flag) for(int i=0;i<6;i++) a[cnt].s[i]=c[(i+n)%6]; else for(int i=0;i<6;i++) a[cnt].s[i]=b[(i+m)%6]; cnt++; } bool flag=false; sort(a,a+cnt,cmp); for(int i=1;i<cnt;i++) { bool flag2=true; for(int j=0;j<6;j++) if(a[i].s[j]!=a[i-1].s[j]) flag2=false; if(flag2){flag=true;break;} } puts(flag?"Twin snowflakes found.":"No two snowflakes are alike."); return 0;}
- poj 3349 Snowflake Snow Snowflakes【HASH】/【最小表示】
- pku 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
- 分号小结(部分)
- 12-2-4进步一小点
- 常用算法五(分支限界法)
- 中国智能家电:遭遇创新考验
- Quartz.NET的管理工具
- poj 3349 Snowflake Snow Snowflakes【HASH】/【最小表示】
- hdu 1181 dfs
- make menuconfig错误scripts/kconfig/lxdialog/checklist.o的解决方法
- native app开发小结
- 人生思考
- 1886
- .NET 定时执行写日志任务解决方案(Timer & Quartz.Net)
- 【转载】互联网太伟大了,X200电池关机或休眠时自放电问题完美解决全过程
- C代码优化方案(转)