首页 > 其他分享 >HDU 5012

HDU 5012

时间:2023-08-16 18:03:25浏览次数:47  
标签:HDU arr int 5012 vis step && include


Dice


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1465    Accepted Submission(s): 749


HDU 5012_#include



Input


There are multiple test cases. Please process till EOF. 

For each case, the first line consists of six integers a 1,a 2,a 3,a 4,a 5,a 6, representing the numbers on dice A. 

The second line consists of six integers b 1,b 2,b 3,b 4,b 5,b 6, representing the numbers on dice B.


 


Output


For each test case, print a line with a number representing the answer. If there’s no way to make two dices exactly the same, output -1.


 



Sample Input


1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 5 6 4 3
1 2 3 4 5 6
1 4 2 5 3 6



Sample Output


0 3 -1



#include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
const int inf=(1<<30);

struct Node
{
    int a,b,c,d,e,f;
    int step;
    friend bool operator < (const Node a,const Node b)
    {
        return a.step>b.step;
    }
};
int arr[8],brr[8];
bool vis[7][7][7][7][7][7];
int bfs(int p,int b,int c,int d,int e,int f)
{
    memset(vis,0,sizeof(vis));
    priority_queue <Node> q;
    Node a;
    a.a=p,a.b=b,a.c=c,a.d=d,a.e=e,a.f=f;
    a.step=0;
    q.push(a);
    vis[a.a][a.b][a.c][a.d][a.e][a.f]=1;
    while(!q.empty())
    {
        Node c=q.top();
        q.pop();
        vis[c.a][c.b][c.c][c.d][c.e][c.f]=1;
        if(c.a==arr[1]&&c.b==arr[2]&&c.c==arr[3]&&c.d==arr[4]&&c.e==arr[5]&&c.f==arr[6])
            return c.step;
        if(c.step>=8)break;
        for(int i=1;i<=4;i++)
        {
            Node b=c;
            if(i==1)
            {
                b.step++;
                b.a=c.d,b.b=c.c;
                b.c=c.a,b.d=c.b;
                if(!vis[b.a][b.b][b.c][b.d][b.e][b.f])
                    q.push(b);
            }
            else if(i==2)
            {
                b.step++;
                b.a=c.c,b.b=c.d;
                b.c=c.b,b.d=c.a;
                if(!vis[b.a][b.b][b.c][b.d][b.e][b.f])
                    q.push(b);
            }
            else if(i==3)
            {
                 b.step++;
                b.a=c.f,b.b=c.e;
                b.e=c.a,b.f=c.b;
                if(!vis[b.a][b.b][b.c][b.d][b.e][b.f])
                    q.push(b);
            }
            else if(i==4)
            {
                b.step++;
                b.a=c.e,b.b=c.f;
                b.e=c.b,b.f=c.a;
                if(!vis[b.a][b.b][b.c][b.d][b.e][b.f])
                    q.push(b);
            }
        }
    }
    return -1;
}
int main()
{
    while(~scanf("%d%d%d%d%d%d",&arr[1],&arr[2],&arr[3],&arr[4],&arr[5],&arr[6]))
    {
        for(int i=1;i<=6;i++)
            scanf("%d",&brr[i]);
        int cnt=bfs(brr[1],brr[2],brr[3],brr[4],brr[5],brr[6]);
        printf("%d\n",cnt);
    }
    return 0;
}



标签:HDU,arr,int,5012,vis,step,&&,include
From: https://blog.51cto.com/u_3936220/7111707

相关文章

  • hdu 5365
    LCPArrayTimeLimit:4000/2000MS(Java/Others)    MemoryLimit:131072/131072K(Java/Others)TotalSubmission(s):1223    AcceptedSubmission(s):338ProblemDescriptions=s1s2...sn,let suffi=sisi+1...sn bethesuffixstartwith......
  • HDU 5500
    ReordertheBooksTimeLimit:4000/2000MS(Java/Others)    MemoryLimit:131072/131072K(Java/Others)TotalSubmission(s):449    AcceptedSubmission(s):294ProblemDescriptionn(n≤19) booksinthisseries.Everybookhasanumberfrom ......
  • HDU 5499(模拟)
    SDOITimeLimit:2000/1000MS(Java/Others)    MemoryLimit:131072/131072K(Java/Others)TotalSubmission(s):500    AcceptedSubmission(s):210ProblemDescriptionn(n≤100) peoplecomestotheSelectandthereis m(m≤50) people......
  • HDU 4893(线段树区间更新)
    Wow!SuchSequence!TimeLimit:10000/5000MS(Java/Others)    MemoryLimit:65536/65536K(Java/Others)TotalSubmission(s):3856    AcceptedSubmission(s):1085ProblemDescriptionRecently,Dogegotafunnybirthdaypresentfromhisnewf......
  • HDU 5495(dfs)
    LCSTimeLimit:6000/3000MS(Java/Others)    MemoryLimit:65536/65536K(Java/Others)TotalSubmission(s):417    AcceptedSubmission(s):216ProblemDescription{a1,a2,...,an} and {b1,b2,...,bn}.Bothsequencesarepermutationof......
  • hdu 4291(矩阵快速幂+循环节)
    AShortproblemTimeLimit:2000/1000MS(Java/Others)    MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):2487    AcceptedSubmission(s):876ProblemDescriptionAccordingtoaresearch,VIMuserstendtohaveshorterfing......
  • HDU 5014
    NumberSequenceTimeLimit:4000/2000MS(Java/Others)    MemoryLimit:65536/65536K(Java/Others)TotalSubmission(s):2075    AcceptedSubmission(s):814SpecialJudgeProblemDescriptionThereisaspecialnumbersequencewhichhasn+1inte......
  • hdU 5024
    WangXifeng'sLittlePlotTimeLimit:2000/1000MS(Java/Others)    MemoryLimit:65536/65536K(Java/Others)TotalSubmission(s):786    AcceptedSubmission(s):474ProblemDescription《DreamoftheRedChamber》(also《TheStoryoftheStone......
  • HDU 5443
    TheWaterProblemTimeLimit:1500/1000MS(Java/Others)    MemoryLimit:131072/131072K(Java/Others)TotalSubmission(s):606    AcceptedSubmission(s):489ProblemDescriptiona1,a2,a3,...,anrepresentingthesizeofthewatersource.Given......
  • HDU 5313
    TheshortestproblemTimeLimit:3000/1500MS(Java/Others)  MemoryLimit:65536/65536K (Java/Others)TotalSubmission(s):1484  AcceptedSubmission(s):686ProblemDescriptionInthisproblem,weshouldsolveaninterestinggame.Atfirst,we hav......