Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
麻烦大牛们帮忙看下程序,没有用哈希,应该是超时才对,不知为什么总是WA// 3349_snowflake.cpp : 定义控制台应用程序的入口点。 #include <iostream> using namespace std; long nums[180050][6]; bool Isfound(long n){ for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ for(int k=0;k<6;k++){ if(nums[i][0]==nums[j][k]){ int count=1; int m=0; int n=k; while(count<=6){ if(nums[i][m%6]==nums[j][n%6]){ if(count==6) return true; } ++count; ++m; ++n; } count=1; m=0; n=k; while(count<=6){ int tn=n; if(n<0) tn+=6; if(nums[i][(m)%6]==nums[j][tn%6]){ if(count==6) return true; } ++m; --n; ++count; } } } } } return false; } int main(){ long n; cin>>n; long temp; for(int i=0;i<n;i++){ for(int j=0;j<6;j++){ cin>>temp; nums[i][j]=temp; } } if(Isfound(n)){ cout<<"Twin snowflakes found."<<endl; } else { cout<<"No two snowflakes are alike."<<endl; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator