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

超时问题~请大家帮忙看看如何改进,谢谢啊...

Posted by coobj2008 at 2011-08-10 11:20:25 on Problem 3349
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;

struct Node
{
	int a[6];
}e[100005];

int is(const Node &c,const Node &d)
{
	int i,j,flag1,flag2;
	flag1=flag2=0;
	for(j=0;j<6;j++)
	{
		for(i=0;i<6;i++)
			if(c.a[(i+j)%6]!=d.a[i]) break;
		if(i==6) 
		{
			flag1=1;
			break;
		}
	}
	for(j=0;j<6;j++)
	{
		for(i=0;i<6;i++)
			if(c.a[(i+j)%6]!=d.a[5-i]) break;
		if(i==6) 
		{
			flag2=1;
			break;
		}
	}
	return (flag1||flag2);
}			

int main()
{
	int i,n,j,flag;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		for(j=0;j<6;j++)
			scanf("%d",&e[i].a[j]);
	flag=0;
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			flag=is(e[i],e[j]);
			if(flag==1)
			{
				printf("Twin snowflakes found.\n");
				return 0;
			}
		}
	}
	if(flag==0) printf("No two snowflakes are alike.\n");
	return 0;
}


					

	

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