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

Re:排序3600ms卡过

Posted by fengjian at 2010-08-10 20:27:59 on Problem 3349
In Reply To:Re:排序3600ms卡过 Posted by:fengjian at 2010-08-10 20:27:33
#include <iostream>
#include <algorithm>
using namespace std;	

struct stu
{
	int a[10];
}s[100002];

bool cmp(stu a1,stu b1)
{
	return a1.a[6]<=b1.a[6];
}

int main()
{
	int i,j,n,k,t,l,sum,ll,kk;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		sum=0;
		for(j=0;j<6;j++)
		{
			scanf("%d",&s[i].a[j]);
			sum+=s[i].a[j];
		}
		s[i].a[6]=sum;
	}
    sort(s,s+n,cmp);

	ll=0;
	kk=1;
	for(i=0;i<n-1;i++)
	{
		l=1;
		if(kk<=i) kk=i+1;
		for(j=kk;j<n;j++)
		{    
			if(s[i].a[6]==s[j].a[6])
			{
				if(l==1) {kk=j;l=0;}
				for(t=0;t<6;t++)
				{
				  for(k=0;k<6;k++)
					  if(s[i].a[(k+t)%6]!=s[j].a[k]) break;
					  if(k>=6) {ll=1;goto aa;}
				}
				for(t=0;t<6;t++)
				{
				  for(k=0;k<6;k++)
					  if(s[i].a[(k+t)%6]!=s[j].a[5-k]) break;
					  if(k>=6) {ll=1;goto aa;}
				}
			}
			else if(s[i].a[6]<s[j].a[6]) break;
		}
	}
aa:; if(ll==1) cout<<"Twin snowflakes found."<<endl;
   else cout<<"No two snowflakes are alike."<<endl;
   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