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

不行,有强迫症,HASH总觉得有bug,不严谨,楼主这种方法,从逻辑上必然成立,不过就是写的太丑,我的比较漂亮

Posted by tjrac6016203284 at 2018-05-08 18:04:28 on Problem 3349
In Reply To:判断雪花是否相同,其实也不难,翻转和移动 6次 就能判断出来。 Posted by:tangguojun at 2017-09-27 23:57:41
#include<iostream>
#include<cstdio>
#include<set>
#include<algorithm>
using namespace std;
struct node
{
    int a[6];
    long long sum;
};
node a[1000010];
bool cmp(node a,node b)
{
    if(a.sum<b.sum)
        return true;
    return false;
}

bool jud(int x,int y)
{
    for(int i=0;i<6;++i)
    {
        int flag=1;
        for(int j=0;j<6;++j)
        {
            if(a[x].a[j]!=a[y].a[(j+i)%6])
            {
                flag=0;
                break;
            }
        }
        if(flag)
            return true;
    }
    for(int i=0;i<6;++i)
    {
        int flag=1;
        for(int j=0;j<6;++j)
        {
            if(a[x].a[j]!=a[y].a[(6-j+i)%6])
            {
                flag=0;
                break;
            }
        }
        if(flag)
            return true;

    }
    return false;
}

int main()
{
    int flag=1,N;
    scanf("%d",&N);
    for(int i=0;i<N;++i)
    {
        scanf("%d%d%d%d%d%d",&a[i].a[0],&a[i].a[1],&a[i].a[2],&a[i].a[3],&a[i].a[4],&a[i].a[5]);
        a[i].sum=0;
        a[i].sum=a[i].a[0]+a[i].a[1]+a[i].a[2]+a[i].a[3]+a[i].a[4]+a[i].a[5];
    }
    sort(a,a+N,cmp);
    int j;
    for(int i=0;i<N&&flag;++i)
    {
        j=i+1;
        while(j<N&&a[i].sum==a[j].sum)
        {
            if(jud(i,j))
            {
                flag=0;
                break;
            }
            ++j;
        }
    }
    if(flag)
        printf("No two snowflakes are alike.\n");
    else
        printf("Twin snowflakes found.\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