Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

麻烦大牛们帮忙看下程序,没有用哈希,应该是超时才对,不知为什么总是WA

Posted by GaryLiang at 2009-10-30 21:05:42 on Problem 3349
// 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator