http://poj.org/problem?id=3349

#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<math.h>
#define N 5000

using  namespace std;
struct node
{
    int a[6];
    int sum;
}mem[100005];
vector< int >str[5000];
inline bool find(int l,int k)
{
    int j;
    for(int i=0;i<str[k].size();++i)
    {   j=str[k][i];
        if(j!=l)
        {
            int b;
            for(b=0;b<6;++b)
            {
                 if(mem[l].a[0]==mem[j].a[b]&&mem[l].a[1]==mem[j].a[(b+1)%6]&&mem[l].a[2]==mem[j].a[(b+2)%6]&&mem[l].a[3]==mem[j].a[(b+3)%6]&&
                    mem[l].a[4]==mem[j].a[(b+4)%6]&&mem[l].a[5]==mem[j].a[(b+5)%6])
                 return true;
                 if(mem[l].a[5]==mem[j].a[b]&&mem[l].a[4]==mem[j].a[(b+1)%6]&&mem[l].a[3]==mem[j].a[(b+2)%6]&&mem[l].a[2]==mem[j].a[(b+3)%6]
                       && mem[l].a[1]==mem[j].a[(b+4)%6]&&mem[l].a[0]==mem[j].a[(b+5)%6])
                 return true;
            }
        }
    }
    return false;
}
int main()
{
    //freopen("data.txt","r",stdin);
    //freopen("A-large-practice.out","w",stdout);
    int n;
    int i;
    int l;
    while(scanf("%d",&n)!=EOF)
    {
        for(l=0;l<n;++l)
        {
            mem[l].sum=0;
            for(i=0;i<6;++i)
            {
                scanf("%d",&mem[l].a[i]);
                mem[l].sum+=mem[l].a[i];
                //cout<<mem[l].sum<<endl;
            }
            //cout<<l<<" "<<mem[l].sum%N<<endl;
            str[mem[l].sum%N].push_back(l);
        }
        for(l=0;l<n;++l)
        {
            if(find(l,mem[l].sum%N))
            break;
        }
        if(l<n)
        {
            printf("Twin snowflakes found.\n");
        }
        else
        {
            printf("No two snowflakes are alike.\n");
        }

    }
    return 0;
}

 

posted on 2012-03-27 20:19  夜->  阅读(196)  评论(0编辑  收藏  举报